This article addresses the residential energy cost optimization problem in smart grid. To date, most of the previous research only consider a partial aspect of the cost optimization problem. As a result, they fail to analyze scenarios when the interconnected components along with their properties have to be considered simultaneously. The proposed model combines these partial models into a single unified cost optimization model. Therefore, it is able to analyze scenarios which are closer to practical implementation. Furthermore, it is useful to analyze the behavior of a population (e.g., smart buildings, smart cities, etc.) and properties of the components for specific scenarios (e.g., the impact of aggregate storage capacity, etc.). It allows energy trading in microgrid which introduces a cost fairness problem. It ensures Pareto optimality among the households which guarantees that no household will be worse off to improve the cost of others. Results show that it can maintain the user preferences and can react to a demand response program by rescheduling the household loads and sources. Finally, the paper addresses the challenge of the computational complexity of the proposed model, showing that solution time increases exponentially with the problem size and proposes possible approaches to solve this.