In smart factories, an increasing number of mobile intelligent devices are deployed to meet the growing demands for flexible manufacturing. These devices, equipped with various sensors, synchronize a substantial amount of data with cloud servers for real-time monitoring and control. Fifth generation mobile networks (5G) combined with multi-access edge computing (MEC) provide the capabilities for multiple connections, large-scale data transmission, and efficient response times, becoming the mainstream network architectures for the needs. Additionally, with the emerging trend of energy-saving, recent works have addressed energy consumption as a significant cost factor. However, most previous studies tended to focus solely on cloud servers, neglecting energy consumption at edge computing and underestimating the impact of heterogeneous mobile device. As the scope of smart factory networks continues to expand, the challenges become increasingly critical. This study presents a private 5G MEC system architecture tailored for smart panel factories. The concerned problem is formulated as an integer programming model, which determines deployment locations and quantities for MEC servers and 5G small cells, including picocells and femtocells, so as to minimize the overall deployment costs while meeting the constraints of connectivity, capacity, latency, coverage, serviceability, and energy consumption. Since the edge server deployment problem is NP-hard, this study further proposes a hybrid metaheuristic algorithm, CSAVNS, which combines the strengths of crow search algorithm (CSA) and variable neighborhood search (VNS). In the global search phase of CSA, the VNS local search is introduced to enhance the algorithm's capabilities. Experimental analysis demonstrates that the proposed CSAVNS outperforms other algorithms in terms of solution solving capabilities.