The primary aim of this paper is to solve the optimization problem \(\min \Vert AX-B\Vert _F\) subject to \({\mathcal {R}}(X)\subseteq {\mathcal {R}}(\mathfrak {X})\) in the Frobenius norm, where \(A\in \mathbb {C}^{m\times n}\) , \(B\in \mathbb {C}^{m\times m}\) and \(\mathfrak {X} \) is a matrix with appropriate properties. In addition, we consider solvability of the dual minimization problem \(\min \Vert XA-B\Vert _F\) according to limitations \({\mathcal {N}}(\mathfrak {X})\subseteq {\mathcal {N}}(X)\) , where \(A\in \mathbb {C}^{m\times n}\) , \(B\in \mathbb {C}^{n\times n}\) and \(\mathfrak {X} \) is appropriate matrix. Our results determine least squares solutions. In addition, we show that this problem has a unique solution expressed by the \(\mathfrak {X}\) -GCEP inverse of A. Special cases of these optimization problems are listed as known results.