It has previously been shown that, at least for non-exceptional Kac-Moody Lie
algebras, there is a close connection between Demazure crystals and tensor
products of Kirillov-Reshetikhin crystals. In particular, certain Demazure
crystals are isomorphic as classical crystals to tensor products of
Kirillov-Reshetikhin crystals via a canonically chosen isomorphism. Here we
show that this isomorphism intertwines the natural affine grading on Demazure
crystals with a combinatorially defined energy function. As a consequence, we
obtain a formula of the Demazure character in terms of the energy function,
which has applications to Macdonald polynomials and q-deformed Whittaker
functions.