Forecasting enables the cost-effective integration of renewable energy sources such as solar and wind. Forecasting daily, monthly, seasonal, and annual data for different locations with varying observation/data samples remains challenging with a single forecasting algorithm. We presented the ensemble-based k-nearest neighbor algorithm for wind and solar power forecasting in this study to respond to the challenges mentioned above. The included k-NNC deep architecture provides nonlinear modeling complexity in solar and wind energy, enabling a more precise estimate of spatial solar and wind energy patterns. Makowski metric analysis was employed to train and optimize the k-nearest neighbor algorithm. The chi-square distance was used to theoretically assess the goodness of fit of the k-nearest neighbor algorithm between expected and observed values. The 5-fold crossvalidation method was utilized to estimate the accurate lasso-penalty strength for high-dimensional solar/ wind data. The ensemble forecasts were combined using 5-fold cross-validation to improve generalization performance, minimizing over-fitting induced by base model correlation. For daily, monthly, seasonal, and annual solar and wind power forecasting, two different climate areas and four distinct experimental setups are presented. The forecasting accuracy of the proposed k-nearest neighbor technique is validated using three performance assessment indices and four existing forecasting models. The mean absolute error of the k-nearest neighbor algorithm generalized linear regression model, one-step-secant backpropagation neural network, decision tree, and BFGS Quasi-Newton backpropagation neural network for solar and wind power forecasting was measured at 1.16, 5.59, 4.22, 1.70, 3.23, and 8.60, 15.81, 40.64, 0.56, and 15.04, respectively. Utilities can anticipate down- and up-ramps in variable renewable energy generation by introducing the k-nearest neighbor algorithm into power system operations, allowing them to cost-effectively balance renewable energy production and load on a daily, monthly, seasonal, and annual basis. This will improve power system dependability, reduce fuel costs, and limit the use of solar and wind resources.