The research of agricultural wireless sensor networks (AWSNs) plays an important role in the field of facility agricultural technology. The temperature and humidity nodes in AWSNs are so tiny that they are limited on computation, network management, information collection, and storage size. Under this condition, task allocation plays a key role in improving the performance of AWSNs to reduce energy consumption and computational constraints. However, the optimization of task allocation is a nonlinearly constrained optimization problem whose complexity increases when constraints such as limited computing capabilities and power are undertaken. In this paper, an elite immune ant colony optimization (EIACO) is proposed to deal with the problem of task allocation optimization, which is motivated by immune theory and elite optimization theory. The EIACO uses ant colony optimization (ACO) to combine the clone operator and elite operator together for the optimization of task allocation. The performances of EIACO with different numbers of temperature and humidity sensor nodes and tasks have been compared by both genetic algorithm (GA) and simulated annealing (SA) algorithm. Simulation results show that the proposed EIACO has a better task execution efficiency and higher convergence speed than GA and SA. Furthermore, the convergence speed of EIACO is faster than GA and SA. Therefore, the whole system efficiency can be improved by the proposed algorithm.