Integration by parts plays a crucial role in mathematical analysis, e.g., during the proof of necessary optimality conditions in the calculus of variations and optimal control. Motivated by this fact, we construct a new, right-weighted generalized fractional derivative in the Riemann–Liouville sense with its associated integral for the recently introduced weighted generalized fractional derivative with Mittag–Leffler kernel. We rewrite these operators equivalently in effective series, proving some interesting properties relating to the left and the right fractional operators. These results permit us to obtain the corresponding integration by parts formula. With the new general formula, we obtain an appropriate weighted Euler–Lagrange equation for dynamic optimization, extending those existing in the literature. We end with the application of an optimization variational problem to the quantum mechanics framework.