Assuming you mean move away from a black hole, so long as the photon hasn't entered the Event Horizon.
Take a baseball. Drop it. The closer it gets to the black hole, the faster it'll be moving. (Ignoring gravitational time-dilation effects, I won't go into those right now.) As it moves more quickly, it gains more kinetic energy. If you throw a baseball away from a black hole, the black hole's gravity will bring it to a halt (and then pull it in,) decreasing its kinetic energy.
The same holds for a photon. Not the speed bit, as they always locally move at c, but the energy bit. You might be wondering how it actually loses the energy, as again, photons always move at c (locally.) Now here's where the time dilation becomes important to our thought experiment.
http://en.wikipedia.org/wiki/Gravitational_redshift
Basically, while a photon moves away from a gravitating body, its frequency decreases. As the energy of a photon is proportional to its frequency, its energy also decreases.