Sustainability can achieve a balance among economic prosperity, social equity, and environmental protection to ensure the sustainable development and happiness of current and future generations; photovoltaic (PV) power, as a clean, renewable energy, is closely related to sustainability providing a reliable energy supply for sustainable development. To solve the problem with the difficulty of PV power forecasting due to its strong intermittency and volatility, which is influenced by complex and ever-changing natural environmental factors, this paper proposes a PV power forecasting method based on eXtreme gradient boosting (XGBoost)–sequential forward selection (SFS) and a double nested stacking (DNS) ensemble model to improve the stability and accuracy of forecasts. First, this paper analyzes a variety of relevant features affecting PV power forecasting and the correlation between these features and then constructs two features: global horizontal irradiance (GHI) and similar day power. Next, a total of 16 types of PV feature data, such as temperature, azimuth, ground pressure, and PV power data, are preprocessed and the optimal combination of features is selected by establishing an XGBoost–SFS to build a multidimensional climate feature dataset. Then, this paper proposes a DNS ensemble model to improve the stacking forecasting model. Based on the gradient boosting decision tree (GBDT), XGBoost, and support vector regression (SVR), a base stacking ensemble model is set, and a new stacking ensemble model is constructed again with the metamodel of the already constructed stacking ensemble model in order to make the model more robust and reliable. Finally, PV power station data from 2019 are used as an example for validation, and the results show that the forecasting method proposed in this paper can effectively integrate multiple environmental factors affecting PV power forecasting and better model the nonlinear relationships between PV power forecasting and relevant features. This is more applicable in the case of complex and variable environmental climates that have higher forecasting accuracy requirements.