The energy harvesting cognitive wireless sensor network (EHCWSN) introduces energy harvesting technology and cognitive radio technology into the traditional wireless sensor network (WSN), which significantly prolongs the working life of the sensor node and effectively alleviates the congestion problem of the unlicensed spectrum. Due to the uncertainty of the energy harvesting process and the behavior of the primary user (PU), how to allocate and manage limited network resources is a crucial problem in the EHCWSN. In this work, a new Q-learning-based channel selection method is proposed for the energy harvesting process and the randomness of the PU's behavior in the sensor network. By continuously interacting and learning with the environment, the method guides the secondary user (SU) to select the channel with better channel quality. Moreover, we also propose a resource management and allocation mechanism with guaranteed QoS requirements for node traffic based on the framework of Lyapunov optimization theory. We design a low-complex online algorithm based on the optimization framework, which is then validated through extensive simulations. The results demonstrate that our design achieves higher accuracy with the QoS guarantee.