The building sector, excluding its industry, is one of the world's largest energy consumers. 2019 accounted for around 30% of the total final energy consumed worldwide. In addition, its CO2 emissions accounted for 28% of the total, as much of the fuel used to generate this final energy is still of non-renewable origin. Currently, there is an extreme need to reduce these pollutant emissions over the next few years due to the global warming problems we are experiencing. In addition, the peak of fossil fuel production is either near or has already been exceeded during the last decade. This will lead to the end of affordable fossil fuels. Therefore, the world must move towards an energy strategy aimed at increasing demand-side efficiency and consuming energy produced from renewable fuels. To this end, implementing mathematical models to help characterise, simulate and predict energy consumption in the building sector is a key step in this energy transition process. Within the framework of this Thesis, a platform for storing and massively analysing energy data has been implemented. Additionally, three more specific use cases have been proposed that refer to some of the most recurrent problems at each of the main geographical levels in the building sector (dwelling, building or district level). The objectives of these use cases are to inform and alert end-users about their energy consumption, optimising energy demand or cost, maximising energy consumption from renewable generation, or inferring apparently unknown energy characteristics of buildings and their occupants. This Thesis presents the data analytics platform designed and developed to deal with the massive analysis of a vast amount of data coming from electricity smart meters. Furthermore, the implemented energy information services for end-users are presented, and the estimated energy savings generated by those services, quantified within the IEE Empowering project, are presented (3 to 22%). Subsequently, three applications are introduced, each one dealing with a specific geographical level. In the first one, a novel methodology to virtually replicate the control of thermostatically-controlled systems is presented. It is applied over a set of residential dwellings and it is based on data-driven models. Some promising outcomes showed during warm conditions (7-15ºC), for example, reducing the usual set-point temperature of the thermostat by 1ºC or 2ºC would lead to energy savings of 18.1% and 36.5% on average, respectively. In the second application, three Model Predictive Control (MPC) strategies have been implemented in different locations in Europe to assess the energy flexibility that can be achieved when a smarter control is applied to existing electricity driven heating or cooling systems in several building typologies and electricity markets. The results showed that electric heat pumps can provide significant demand response flexibility in the respective analysed electricity markets. However, they sometimes have problems regarding response time and reliability, which can affect their availability for the standby electricity market. Finally, in the third and last case study, a methodology for characterising the electricity consumption of large sets of buildings, e.g. entire districts or postal codes, is presented. The methodology is based on statistical analysis of the aggregated hourly energy consumption of the whole area of interest, as well as its correlation against meteorological information, cadastral data and socio-economic characteristics. This methodology has been validated to interpret the main drivers of electricity consumption along the whole province of Lleida (Spain).