This study introduces a novel two-stage hybrid optimization framework aimed at enhancing the sustainability of 90-degree slot milling operations on AZ31 magnesium alloy. The framework systematically combines the Taguchi method for experimental design, stepwise regression for predictive modeling, nondominated sorting genetic algorithm II for multiobjective optimization, analytic hierarchy process for weighting sustainability indicators, and gray relational analysis for final solution selection. In the first stage, economic and environmental objectives are optimized independently. In the second stage, these objectives are consolidated using weights derived through the analytic hierarchy process and reoptimized using the nondominated sorting genetic algorithm II. Gray relational analysis is employed to identify the most balanced solution from the Pareto optimal set. The developed regression models demonstrate high predictive accuracy, and experimental validation confirms the practical effectiveness of the framework. Results show a 78% improvement in economic and a 90% improvement in environmental sustainability compared to baseline conditions. The framework's modular structure and adaptability to other machining processes make it a valuable tool for promoting sustainable manufacturing practices. Highlights: • A two-stage optimization approach is used to identify optimal machine parameters that balance economic and environmental goals. • The framework combines NSGA-II and GRA to enhance decision-making in parameter optimization. • Significant improvements in both economic (78%) and environmental (90%) performance are achieved compared to the worst machine setting in the parent dataset. • Experimental validation confirms the framework's practical applicability with prediction errors within 5%.