Energy supply security is one of the strategic issues of all states. In Iran, about 35 % of the total energy is consumed by the residential and commercial sectors. According to the importance of residential and commercial sectors in energy consumption, this paper develops different models to analyze energy demand of residential and commercial sectors. The GA and PSO energy demand estimation models (GA-DEM, PSO-GEM), a suitable model for this study, is used to estimate future energy demand of the sectors. Energy demand of these sectors has been estimated in two various forms, exponential and linear models. These sectors consumption in Iran from 1967 to 2010 is considered as the case of this study. The available data are partly used for finding the optimal, or near-optimal values of the coefficient parameters (1967–2006) and partly for testing the models (2007–2010). Our results show that PSO-DEM exponential model with inputs including, value added of all economic sectors, value of made buildings, the population and the electrical and fuel appliance price index using the mean absolute percentage error on test data is the most suitable model. Finally, based on the best scenario, the energy demand of residential and commercial sectors is estimated 1718 mega barrel of crude oil equivalent (MBOE) (1 barrel = 0.159 m3) up to the year 2032.