Energy demand has increased significantly in the recent years due to the emerging of new technologies and industries, in particular in the developing countries. This increase requires much more developed power grid system than the existing traditional ones. Smart grid (SG) offers a potential solution to this problem. Being one of the most needed and complex cyber-physical systems (CPS), SG has been addressed exhaustively by researchers, from different views and aspects. However, energy optimization yet needs much more studying and examination. Therefore, this chapter presents a comprehensive investigation and analysis of the state-of-the-art developments in SG as a CPS with emphasis on energy optimization techniques and challenges. It also surveys the main challenges facing the SG considering CPS factors and the remarkable accomplishments and techniques in addressing these challenges. In addition, the document contrasts between different techniques according to their efficiency, usage, and feasibility. Moreover, this work explores the most effective applications of the SG as a CPS.