This paper presents an optimization method based on genetic algorithm for the energy management inside buildings developed in the frame of the project Smart Living Lab (SLL) in Fribourg (Switzerland). This algorithm optimizes the interaction between renewable energy production, storage systems and energy consumers. In comparison with standard algorithms, the innovative aspect of this project is the extension of the smart regulation over three simultaneous criteria: the energy self-consumption, the decrease of greenhouse gas emissions and operating costs. The genetic algorithm approach was chosen due to the large quantity of optimization variables and the non-linearity of the optimization function. The optimization process includes also real time data of the building as well as weather forecast and users habits. This information is used by a physical model of the building energy resources to predict the future energy production and needs, to select the best energetic strategy, to combine production or storage of energy in order to guarantee the demand of electrical and thermal energy. The principle of operation of the algorithm as well as typical output example of the algorithm is presented.