A method for simultaneous optimization of energy demand and energy supply in buildings