Energy efficiency is treated as an important performance metric in wireless communication systems, and selecting the appropriate RF chains plays a vital role in maximizing overall system performance, energy efficiency , and spectral efficiency. To maximize energy efficiency and spectral efficiency, a two-level optimization technique for RF chain selection and beamforming is proposed in this paper. In the first level, RF chain selection is performed using particle swarm optimization (PSO) algorithm to maximize system rate. The selected RF chains are then used in the second level, where a two-stage deep learning-based Beamform-ing Neural Network (BFNN) is employed to optimize the beamforming process while being robust to imperfect channel state information (CSI). The BFNN takes the estimated CSI as input and outputs the optimized analog beamformer. The proposed BFNN is trained using a loss function tailored for beamforming optimization. Experimental results validate the effectiveness of the proposed method, showcasing significant improvements in spectral efficiency, while mitigating the effects of imperfect CSI. The spectral efficiency with and without RF selection using PSO is 51.5439 and 47.7258 respectively at SNR of 20dB. This approach provides an efficient and robust solution for RF chain selection and beamforming optimization in wireless communication systems.