We consider managing the freshness of status updates sent from a source (such as a sensor) to a monitoring node. The time-varying availability of energy at the sender limits the rate of update packet transmissions. At any time, the age of information is defined as the amount of time since the most recent update was successfully received. An offline solution that minimizes not only the time average age, but also the peak age for an arbitrary energy replenishment profile is derived. The related decision problem under stochastic energy arrivals at the sender is studied through a discrete time dynamic programming formulation, and the structure of the optimal policy that minimizes the expected age is shown. It is found that tracking the expected value of the current age (which is a linear operation), together with the knowledge of the current energy level at the sender side is sufficient for generating an optimal threshold policy. An effective online heuristic, Balance Updating (BU), that achieves performance close to an omniscient (offline) policy is proposed. Simulations of the policies indicate that they can significantly improve the age over greedy approaches. An extension of the formulation to stochastically formed updates is considered.