In this paper, network function virtualization (NFV) is identified as a promising key technology, which can contribute to energy-efficiency improvement in 5G networks. An optical network supported architecture is proposed and investigated in this paper to provide the wired infrastructure needed in 5G networks and to support NFV toward an energy efficient 5G network. In this paper, the mobile core network functions, as well as baseband function, are virtualized and provided as VMs. The impact of the total number of active users in the network, backhaul/fronthaul configurations, and VM inter-traffic are investigated. A mixed integer linear programming (MILP) optimization model is developed with the objective of minimizing the total power consumption by optimizing the VMs location and VMs servers' utilization. The MILP model results show that virtualization can result in up to 38% (average 34%) energy saving. The results also reveal how the total number of active users affects the baseband virtual machines (BBUVMs) optimal distribution whilst the core network virtual machines (CNVMs) distribution is affected mainly by the inter-traffic between the VMs. For real-time implementation, two heuristics are developed, an energy efficient NFV without CNVMs inter-traffic (EENFVnoITr) heuristic and an energy efficient NFV with CNVMs inter-traffic (EENFVwithITr) heuristic, both produce comparable results to the optimal MILP results. Finally, a genetic algorithm is developed for further verification of the results.