This paper presents a novel strategy for decoupling the attitude and orbit equations of a CubeSat for rendezvous and docking with an uncontrollable cooperative target. For computing a safe trajectory, the proposed control algorithm takes into account the solar energy received by the CubeSat. The CubeSat is equipped with a thruster for orbit maneuvers, magnetic coils for attitude control, and four fixed single-sided rectangular solar panels. The coupled dynamics arising from the dynamical model of the spacecraft is solved using a novel weighted vector-based approach. This paper presents a linearized nonlinear optimal control problem arising in small spacecrafts while trying to maximize solar energy input in the rendezvous and docking process. An intermediate orbit is defined and used to divide the problem into two different optimal control problems: rendezvous optimization and docking optimization problems. A geometrical approach based on the shape of the chaser and the target is contemplated for collision avoidance while docking. The proposed controller design is modified whenever the sunlight is obstructed by the Earth, and the maneuvering controls are redesigned accordingly for optimal rendezvous and docking. Numerical simulations have been carried out to show the efficacy of the proposed concept for steering the trade-off between solar energy and control input during the rendezvous and docking of CubeSat with a tumbling target.