This paper studies optimal control in a sensor network system consisting of mobile robots to minimize the overall energy consumption of the whole network. With communication energy cost and mobility energy cost taken into consideration, the problem is formulated as an optimal control of a hybrid system, which is solved by switched Linear Quadratic Regulator (LQR). Though switched LQR obtains globally optimal solution, the computational complexity is too high to implement the algorithm when the control horizon expands. For this reason, we resort to a switched system version of Receding Horizon Control (RHC), which is stable and provides a solution close to the optimal one. Finally, in order to attenuate the complexity due to the large networked system, the centralized RHC is modified into a distributed algorithm, which converges to a solution that can approximate the optimizer quite well as verified by simulations.