Cell-free massive MIMO (CF-mMIMO) network and its user-centric (UC) version are considered as promising techniques for the next generations of wireless networks. However, fronthaul and backhaul assignments are challenging issues in these networks. In this paper, energy efficiencies of uplink transmission for the CF- and UC-mMIMO networks are studied, wherein access points (APs) are connected to aggregation nodes (ANs) through radio frequency (RF) and/or free-space optic (FSO) fronthauls, and the ANs are connected to a central processing unit via fiber backhauls. The achievable data rates are derived by taking into account the effects of hardware non-ideality at the APs and ANs, FSO alignment and weather conditions. To have a robust and energy-efficient network, especially in the presence of FSO misalignment and adverse weather conditions, firstly, a cognitive RF--FSO fronthaul assignment algorithm is proposed at the cost of sharing the available RF bandwidth between the access and fronthaul links. Then, optimal power allocations at the users and APs are investigated, and two analytical approaches are proposed to solve the non-convex optimization problem. Through numerical results, we have discussed how utilizing the cognitive RF--FSO fronthaul assignment achieves higher energy efficiency compared to that of FSO-only, RF-only, or simultaneously using RF and FSO fronthaul links, e.g., achieving up to $198\%$ higher energy efficiency under unfavorable conditions. Moreover, the effects of FSO misalignment, weather conditions, and power allocations on the performances of the CF- and UC-mMIMO networks are discussed.