A dual-hop cognitive (secondary) relaying system incorporating collaborative spectrum sensing to opportunistically switch between data transmission and energy harvesting is introduced. The secondary relays, first scan the wireless channel for a primary network activity, and then convey their reports to a secondary base station (SBS). Afterwards, the SBS, based on these reports and its own estimation, decides cooperatively the presence of primary transmission or not. In the former scenario, all secondary relays start to harvest energy from the transmission of one or more primary nodes. In the latter scenario, the system initiates secondary communication via a best relay selection policy. The performance of the proposed scheme is thoroughly investigated by assuming realistic channel conditions, i.e., non-identical link-distances and outdated channel estimation, while its overall energy consumption is evaluated, indicating the efficiency of the switching approach.