In this paper, the optimal trajectory and deployment of multiple unmanned aerial vehicles (UAVs), used as aerial base stations to collect data from ground Internet of Things (IoT) devices, is investigated. In particular, to enable reliable uplink communications for IoT devices with a minimum energy consumption, a new approach for optimal mobility of the UAVs is proposed. First, given a fixed ground IoT network, the total transmit power of the devices is minimized by properly clustering the IoT devices with each cluster being served by one UAV. Next, to maintain energy-efficient communications in time-varying mobile IoT networks, the optimal trajectories of the UAVs are determined by exploiting the framework of optimal transport theory. Simulation results show that by using the proposed approach, the total transmit power of IoT devices for reliable uplink communications can be reduced by 56% compared to the fixed Voronoi deployment method. Moreover, our results yield the optimal paths that will be used by UAVs to serve the mobile IoT devices with a minimum energy consumption.