Climate change, the finiteness of fossil fuels, the unreliability of renewable energies, technological progress and political requirements lead to the constant need to rethink the energy supply. In this paper we focus on the design of the energy supply when planning new buildings like storehouses or office buildings. For the components of a building's energy supply we have to select the types of energy production (solar power, heat pumps, fuel-based generators, wind turbines, geothermal energy, power grids, and so on), the energy buffers (batteries, heat stores), the capacity or rated power of the components and the actual devices. The choice should be an optimal compromise between the conflicting objectives low investments and low operating costs. To obtain a sufficiently precise estimation of the operating costs we simulate the load of the components during one or several years. We assume that the energy demand is known or authoritatively estimated for each hour of a year. For each such time step we have to solve the problem of controlling the components to satisfy the current demand based on the controls' state and a prediction of the future demand. We present a mathematical model and solution approach for the component control problem as well as the superordinate component selection problem.