This paper addresses the energy management of a standalone renewable energy system. The system is configured as a microgrid, including photovoltaic generation, a lead-acid battery as a short term energy storage system, hydrogen production, and several loads. In this microgrid, an energy management strategy has been incorporated that pursues several objectives. On the one hand, it aims to minimize the amount of energy cycled in the battery, in order to reduce the associated losses and battery size. On the other hand, it seeks to take advantage of the long-term surplus energy, producing hydrogen and extracting it from the system, to be used in a fuel cell hybrid electric vehicle. A crucial factor in this approach is to accommodate the energy consumption to the energy demand and to achieve this, a model predictive control (MPC) scheme is proposed. In this context, proper models for solar estimation, hydrogen production, and battery energy storage will be presented. Moreover, the controller is capable of advancing or delaying the deferrable loads from its prescheduled time. As a result, a stable and efficient supply with a relatively small battery is obtained. Finally, the proposed control scheme has been validated on a real case scenario.