Recent natural disasters and man-made attacks have imposed substantial challenges on power distribution companies and consumers. The integration of photovoltaic (PV) systems into power distribution networks has risen due to environmental, technical, and economic factors. Additionally, technological advancements have made it possible to provide reactive power using PV systems and battery energy storage (BES) systems. This article proposes a comprehensive framework for the optimal allocation of PV and BES systems within the power distribution system to minimize energy losses and energy not served (ENS) during normal conditions, as well as load interruption under emergency conditions. The framework models the formation of small microgrids, accounting for operational and physical limitations, coordinating them with the network recovery process, and considering various production and load scenarios to maximize the restoration of interrupted loads during emergency conditions. An analysis has been conducted to determine the penetration levels of BES in power distribution systems under these conditions. A Mixed-Integer Quadratic Programming (MIQP) formulation is employed for cost optimization, with the model coded in MATLAB and implemented on a modified IEEE 33-bus network. Results demonstrate that the proposed method significantly enhances the distribution network's resilience during emergencies, achieving a 22.3% reduction in load interruptions and a 26.5% decrease in associated costs. Additionally, energy losses are reduced by 6.7%, while ENS improves by 7.2% compared to configurations optimized solely for normal conditions. This research underscores the importance of strategically integrating PV and BES systems to improve performance metrics in normal and emergency scenarios within power distribution networks.