The Internet of Things (IoT) is playing a pivotal role in transforming various industries, and Wireless Sensor Networks (WSNs) are emerging as the key drivers of this innovation. This research explores the utilization of a heterogeneous network model to optimize the deployment of sensors in agricultural settings. The primary objective is to strategically position sensor nodes for efficient energy consumption, prolonged network lifetime, and dependable data transmission. The proposed strategy incorporates an offline model for placing sensor nodes within the target region, taking into account the coverage requirements and network connectivity. We propose a two-stage centralized control model that ensures cohesive decision making, grouping sensor nodes into protective boxes. This grouping facilitates shared resource utilization, including batteries and bandwidth, while minimizing box number for cost-effectiveness. Noteworthy contributions of this research encompass addressing connectivity and coverage challenges through an offline deployment model in the first stage, and resolving real-time adaptability concerns using an online energy optimization model in the second stage. Emphasis is placed on the energy efficiency, achieved through the sensor consolidation within boxes, minimizing data transmission hops, and considering energy expenditures in sensing, transmitting, and active/sleep modes. Our simulations on an agricultural farmland highlights its practicality, particularly focusing on the sensor placement for measuring soil temperature and humidity. Hardware tests validate the proposed model, incorporating parameters from the real-world implementation to enhance calculation accuracy. This study provides not only theoretical insights but also extends its relevance to smart farming practices, illustrating the potential of WSNs in revolutionizing sustainable agriculture.