A set of capacitated Battery Electric Vehicles (BEVs) carry out pickup and delivery operations with time windows constraints. The energy needed to recharge the batteries of these vehicles is produced in a production unit (p.u.) not far from the area where these vehicles operate. Additional batteries are available at the p.u., where vehicles can go and swap their batteries. Pickup and delivery operations must be planned over a time horizon divided into periods. In each period it must be decided how much energy to give to the batteries that are at the production unit. Also, if the energy produced is in excess of that required by the batteries, this excess can be sold to the general network at a profit. If the energy required by the batteries is greater than the energy produced, an unlimited amount of energy can be bought from the general network. The objective of the problem is to plan vehicle routes to meet all pickup and delivery demands while maximizing the profit that is made from the energy sold over the time horizon. We divide the problem into two sub-problems: the routing sub-problem and the energy management sub-problem. The routing sub-problem is solved heuristically by generating a restricted number of trips. We call trip a couple (r,h) where r is a path between two nodes and h is the starting period of the path. There are four kinds of trips, based on the starting and ending node: trips that start from the depot and arrive to the p.u., trips that start from (and end to) the p.u., trips that start from the p.u. and end at the depot, trips that start from (and end to) the depot. Trips are generated by taking into account the time constraints for the requests and the capacity constraints for the vehicles. The energy management sub-problem is solved by formulating it as a MILP where in each period it must be decided how much energy to give to the batteries, how much energy to sell or buy and which trips are used. The solution method consists of three steps: the routing sub-problem is solved, then the MILP is solved and finally the solution is possibly improved by modifying the routes of some vehicles.