In this paper, using edge processing in IoT network ,a method to decide on task offloading to edge devices and improve management of consuming energy in network of edge devices is introduced. First, by defining the problem of maximizing utility and then by decomposing it based on the status of task offloading from end devices to smart gateway with the lowest battery consumption and the possible lowest use of the communication bandwidth, independent optimal models are obtained and then combining. Then the general problem of maximizing the usefulness and increasing the lifetime of the end devices with restrictions of processing time and energy resources will be obtained. Due to the unknown environment of the problem and how the end devices and the edge of the network, an iterative reinforcement learning algorithm is used to generate the optimal answer in order to maximize the utility gain.The results show the existence of processing overhead and network load with increasing number of devices. The proposed method, while improving energy consumption in existence of a small number of devices in end of edge, reduces latency and increases processing speed and maximizes system performance compared to the central cloud system. The operating efficiency of the whole system is improved by 36% and the energy consumption at the edge of the network is optimized by 12.5%. It should be noted that, with the addition of a large number of end devices, our method outperforms similar works.