This research addresses the energy cost optimization problem in the smart grid from the users' perspective. We first propose a unified model which integrates the partial aspects of previous research in a single cost optimization model. It considers the components which have significant impact on cost optimization, e.g., storage, renewables, microgrid, etc. The model utilizes load and source scheduling, and energy trading strategies for cost optimization. It also addresses the inconvenience created to the users by delaying certain tasks. The model enables Peer-to-Peer (P2P) energy trading among the participating households in the microgrid. In P2P trading, the households determine the microgrid energy price and quantity to minimize the total cost. On the other hand, P2P trading potentially results in an unfair cost distribution among the participating households. We address this unfair cost distribution problem by employing Pareto optimality, ensuring that no households will be worse off to improve the cost of others. However, the optimal solution approach of the unified model is a non-convex Mixed Integer Nonlinear Programming (MINLP) problem. Our results show that, even for small problem sizes, the solution time increases exponentially. Hence, it cannot be utilized to solve practical scenarios. To address this problem, we also propose a bi-linear model which provides an approximate solution within a realistic timeframe. Its complexity is less than the unified model because it works with multiple lower dimensional convex solution spaces. Our results show that the solution time of the bi-linear model is very low (mostly less than a minute) compared to the optimal model. Moreover, for real datasets, 99% of the solutions generated by the bi-linear model are optimal solutions. Finally, we used real datasets of Ottawa to evaluate the impact of renewables and storage in the microgrid. Our results show that P2P energy trading is beneficial if the households have both storage and renewables. In the presence of renewables, increased storage capacity increases cost savings until it reaches a saturation point. Our findings could be helpful for policy makers to design programs and initiatives for the households to accelerate the adoption of storage and renewables in the smart grid.