Abstract Future power systems require a change from a “vertical” to a “horizontal” structure, in which the customer plays a central role. As buildings represent a substantial aggregation of energy consumption, the intertwined operation of the future power grid and the built environment is crucial to achieve energy efficiency and sustainable goals. This transition towards a so-called smart grid (SG) requires advanced building energy management systems (BEMS) to cope with the highly complex interaction between two environments. This paper proposes an agent-based approach to optimize the inter-operation of the SG–BEMS framework. Furthermore a computational intelligence technique, i.e. Particle Swarm Optimization (PSO), is used to maximize both comfort and energy efficiency. Numerical results from an integrated simulation show that the operation of the building can be dynamically changed to support the voltage control of the local power grid, without jeopardizing the building main function, i.e. comfort provision.