A Method for Simultaneous Optimization of Energy Demand and Energy Supply in Buildings