A finite horizon optimal packet scheduling problem with data and energy causality constraints is posed. The slotted structure of the problem makes discrete time stochastic dynamic programming suitable for obtaining its optimal solution. This structure also enables an offline optimal solution that facilitates an online scheduling heuristic. The online heuristic, which does not require prior knowledge of data and energy arrival statistics, is observed (via simulations) to perform closely to the online optimal. The simulations also exhibit that policies designed for longer-term optimal performance can fail in the short term and perform much poorly with respect to the online scheduling heuristic.