Energy systems are undergoing radical changes that have resulted in buildings being regarded as proactive players with the potential to contribute positively to energy networks. This study investigates the role of active buildings (ABs) as prosumers in energy systems by introducing a building-to-building (B2B) strategy for energy exchange between residential units, as well as a building-for-grid (B4G) model by exploiting the demand flexibility of residential microgrids (RMGs). The mid-market rate mechanism is adopted to produce local market price signals at RMG level. A robust rolling horizon controller is developed for real-time energy management of a community of ABs. This control philosophy can improve the robustness of the RMG in face of real-time weather and energy price prediction errors. The proposed method is a multi-level optimisation which pursues multiple goals while making a trade-off between operational cost and occupant comfort. Finally, the repercussions of COVID-19 induced power consumption resulting from changing lifestyle and building occupancy profile is analysed by the proposed method as a case study. The results show that the proposed B2B and B4G strategy can reduce energy bills by 18.45%, while notable robust real-time control and computational efficiencies are achieved when benchmarked against conventional methods.