In her book Warped Passages Lisa Randall uses a ball being thrown up in a brilliant explanation of red shift. As the ball rises, it loses kinetic energy but gains gravitational potential. It slows down. But a photon of light escaping from a gravitational field cannot lose kinetic energy because it has to move at the constant speed of light. So to have some energy to transform into potential it uses the E=hf equation for the quantum energy of a photon. If its frequency reduces - ie if it is shifted to the red end of the spectrum - it has transferred some of that energy.