Now that we have our rate of climb under control, it is a simple matter to leverage this ability to control our absolute altitude.
The input to our altitude PID controller is the difference (error) between our current altitude and our goal altitude. The output is the rate of climb needed to drive our altitude error to zero.
Clearly, our climb rate will be zero when we stabilize on the target altitude. Because our output variable will be zero when our error is zero, we can get by with only a proportional control component.
All we need to do is calculate a desired rate of climb that is proportional to how far away we are from the target altitude. This is a simple proportional altitude controller that sits on top of our slightly more complicated rate of climb controller.
Thus we use the difference in altitude to determine a climb rate and we use the desired climb rate to determine elevator position.