An energy optimization method and control apparatus may be used in a single building or a group of buildings to optimize utility-supplied and renewable sources in order to minimize the total energy cost. Simultaneously, it may also produce and store energy, such as electricity or hydrogen, that can be used to fuel vehicles, provide a means for independent production of household energy needs, or both. Various factors, such as the production of thermal energy and electricity from the renewable sources, the current store of stored energy, the current and expected thermal and electricity requirements of the building (based on a profile), the current and expected electricity loads of the equipment used to process stored energy, the expected thermal and electricity generating capacity of the renewable sources and other factors can be used to determine the mix of renewable-based and utility-based energy that minimizes the total energy cost.