Striving to mitigate CO2 emissions in a cost-effective manner, the European Union (EU) has unprecedentedly emphasized, through its directive 2010/31/EU (revised in 2016), energy efficiency improvement in the building sector, responsible for 36% CO2 emissions in the EU. This directive supports renewable energy sources (RES) integration, imposing that, by the end of 2020, new buildings must be nearly zero-energy buildings (nZEBs), meaning that their on-site RES energy production and consumption be yearly nearly balanced. To achieve this goal, buildings are being equipped with RES and possibly energy storage devices. To ensure nZEB stakeholders compliance and investment profitability, it is vital to design an efficient energy management system (EMS) to optimally steer RES, storage, and deferrable loads (smart appliances, electric vehicles, heat pumps). Besides, the paradigm shift from purely energy consumer building to prosumer nZEB requires the optimal nZEB integration in the smart power grid, i.e. re-examining and exploiting their win-win interaction modes. These ideas are properly aligned with the national strategy and roadmap up to 2050, proposed in late 2016 by Jeremy Rifkin’ consultancy group, in the frame of the third industrial revolution plan in Luxembourg, for both smart sustainable buildings (i.e. an advanced version of nZEBs) and smart energy grids. Responding to these key challenges, the three-fold research question addressed in this project is how to optimally design and operate the energy management system of a new or existing nZEB while taking into account its optimal integration into the smart power grid. To accomplish these three objectives the project proposes novel contributions to both optimization problem formulations (mixed-integer linear/nonlinear programming embedding life cycle assessment-based environmental impacts of various renewable energy and storage technologies) and solution methodologies (model predictive control, rolling horizon, suitable linearization techniques). Besides contributions to scientific knowledge, another major project outcome consists in three prototypes to be further refined to become user-friendly tools for nZEB stakeholders or smart grid operators. These prototypes will be tested on real world case studies, for nZEBs, from Denmark and Luxembourg and, for smart energy grid, from Luxembourg. One prototype will be further tested and validated in close to real-life conditions at the Energy laboratory at the University of Luxembourg.