Hybrid renewable energy systems with photovoltaic and energy storage systems have gained popularity due to their cost-effectiveness, reduced dependence on fossil fuels and lower CO2 emissions. However, their techno-economic advantages are crucially dependent on the optimal sizing of the system. Most of the commercially available optimization programs adopt an algorithm that assumes repeated weather conditions, which is becoming more unrealistic considering the recent erratic behavior of weather patterns. To address this issue, a data-driven framework is proposed that combines machine learning and hybrid metaheuristics to predict weather patterns over the lifespan of a hybrid renewable energy system in optimizing its size. The framework uses machine learning tree ensemble methods such as the cat boost regressor, light gradient boosting machine and extreme gradient boosting to predict the hourly solar radiation and load demand. Nine different hybrid metaheuristics are used to optimize the hybrid renewable energy system using forecasted data over 15 years, and the optimal sizing results are compared with those obtained from 1-year data simulation. The proposed approach leads to a more realistic hybrid renewable energy system capacity that satisfies all system constraints while being more reliable and environmentally friendly. The proposed framework provides a robust approach to optimizing hybrid renewable energy system sizing and performance evaluation that accounts for changing weather conditions over the lifespan of the system.