Distributed generators (DGs) have a high penetration rate in distribution networks (DNs). Understanding their impact on a DN is essential for achieving optimal power flow (OPF). Various DG models, such as stochastic and forecasting models, have been established and are used for OPF. While conventional OPF aims to minimize operational costs or power loss, the “Dual-Carbon” target has led to the inclusion of carbon emission reduction objectives. Additionally, state-of-the-art optimization techniques such as machine learning (ML) are being employed for OPF. However, most current research focuses on optimization methods rather than the problem formulation of the OPF. The purpose of this paper is to provide a comprehensive understanding of the OPF problem and to propose potential solutions. By delving into the problem formulation and different optimization techniques, selecting appropriate solutions for real-world OPF problems becomes easier. Furthermore, this paper provides a comprehensive overview of prospective advancements and conducts a comparative analysis of the diverse methodologies employed in the field of optimal power flow (OPF). While mathematical methods provide accurate solutions, their complexity may pose challenges. On the other hand, heuristic algorithms exhibit robustness but may not ensure global optimality. Additionally, machine learning techniques exhibit proficiency in processing extensive datasets, yet they necessitate substantial data and may have limited interpretability. Finally, this paper concludes by presenting prospects for future research directions in OPF, including expanding upon the uncertain nature of DGs, the integration of power markets, and distributed optimization. The main objective of this review is to provide a comprehensive understanding of the impact of DGs in DN on OPF. The article aims to explore the problem formulation of OPF and to propose potential solutions. By gaining in-depth insight into the problem formulation and different optimization techniques, optimal and sustainable power flow in a distribution network can be achieved, leading to a more efficient, reliable, and cost-effective power system. This offers tremendous benefits to both researchers and practitioners seeking to optimize power system operations.