Actually, you change the speed of your robot by means of the power your controller is applying to robot motors. This is normally done by Pulse Width Modulation (PWM), more power, more speed.
We can use the encoder to measurement the actual speed of the robot e.g. counting the pulses by second, and implement a control loop to control that speed, normally a simple P loop (Proportional Loop) works fine.
You can use Dead-Reckoning to compute the distance traveled by your robot. Dead-Reckoning uses the pulses of the encoder to compute distance traveled and even orientation of the robot and it is easily implemented.
It is a little bit long to type here but you can check up the following paper, just read the first 5 pages:
http://www.cs.biu.ac.il/~galk/teaching/s...
Basically the encoder pulses will depend on the wheel diameter, resolution of the encoder (number of counts per turn) and gear ratio between the encoder and the wheel.
So, to make what you want using only encoders you have to know the distances involved and program your robot to travel at certain speed up hill and in another speed down hill, measuring the distance traveled by means of the encoder counts and controlling the speed also by them.
Your program has to be "multitasking" since you have to counting encoder pulses, control speed, measure speed, produce PWM signal, and following a line, which could be too much for an only task.
If you specific your robot plaform, I can give you more details about what to do.