This paper investigates an optimal mode selection policy for cognitive radio sensor networks powered by RF energy harvesting. The RF energy harvesting enables the sensor node to operate with a potentially perpetual lifetime. We assume that the sensor node harvests RF energy received from the primary network and it cannot carry out RF energy harvesting and opportunistic spectrum access at the same time. Therefore, the sensor node should decide whether to access the spectrum or to harvest RF energy in each time slot to maximize an expected total throughput. We develop the optimal mode selection policy by casting this decision making problem in the framework of partially observable Markov decision process (POMDP). Numerical results show that the developed optimal policy finds a balance between obtaining the immediate throughput and harvesting the RF energy for future use.