Recently, mobile devices are equipped with wireless energy charging capability. They can be charged wirelessly by chargers located at different locations. The prices that the chargers apply to the mobile user/node can be changed, e.g., due to the implementation of demand side management in smart grid environment. The mobile node can use this price information (e.g., obtained through wireless communication) to make its charging decision accordingly. In this paper, we study an optimal wireless energy charging policy for the mobile node. The mobile node's objective is to minimize the cost due to the price of using charging service from chargers and the cost of having not enough energy. We formulate and solve a Markov decision process to obtain such an optimal policy. Additionally, we analytically prove that the optimal charging policy has a threshold structure. That is, the mobile node will use the charging service if its energy level is below a certain threshold. The performance evaluation shows the proposed energy charging policy achieves much better performance compared with a naive policy of always charging.