The optimization of energy use in family homes and public buildings is an ongoing topic of discussion. State-of-the-art research has almost always focused on reducing the consumption of heating systems, air-conditioning or lighting. Despite their importance, user-related variables, such as comfort, are normally not included in the optimization process. These aspects should be considered to be able to e↵ectively minimize energy consumption. Thus, there is a need for a comprehensive energy optimization approach, one that will consider both climatological factors and user behaviour. Learning about user behaviour is key to e↵ective optimization. In this work, the proposed architecture's capacity to organize Virtual Agent Organizations (VAO) allows it to adapt to highly variable user behavior and preferences. This agent methodology has the ability to manage Wireless Sensor Networks (WSNs), Artificial Neural Networks (ANN) and Case-Based Reasoning (CBR) to obtain user preferences and predict their behaviour in the home or building. The proposed approach has been tested in two di↵erent buildings, a traditional-construction house and a modular home, obtaining savings of 30.16% and 13.43%, respectively. These results validate the proposed mixed approach of temperature adjustment algorithms together with the extraction of user behavior patterns for the establishment of a threshold based on preferences.