Modern polygeneration systems have increased the flexibility of production in energy systems. In this paper, a polygeneration system for producing power, freshwater, and methanol using solar and waste resources is defined. By using waste heat recovery in Brayton, Steam Rankine, organic Rankine, and Kalina systems, power has been produced in the proposed system. Methanol is also provided by using CO2 capture from exhaust flue gases and hydrogen produced by Proton Exchange Membrane electrolyzer. The integration of microbial fuel cells, multi-effect distillation, and reverse osmosis desalination has been used for muddy seawater recovery and freshwater production. The proposed system has been analyzed using energy, exergy, exergeoeconomic, and exergoenvironmental (4E) analyses for three biomass fuels. The Multi-Objective Dragonfly Algorithm, Multi-Objective Thermal Exchange Optimization, Multi-objective Salp Swarm Algorithm, and Multi-Objective Water Cycle Algorithm have been used for the optimization of the whole system. In the end, the studied system has been modeled hourly. In this research, machine learning has been used to facilitate modeling the desalination sector, CO2 capture sector, and methanol production sector. Also, it has played a significant role in reducing optimization run time. The modeling results show that Municipal solid waste is the most economical fuel for the study system with a payback of 4.28 years. Date palm waste has also caused fewer environmental impacts than other fuels. The comparison of the results of optimization indicates that Multi-objective Salp Swarm Algorithm is the fastest method for system optimization and can lead to 4.04% and 7.16% improvement in the system cost and environmental impact rate. In general, the energy and exergy efficiencies of the system in the optimal state are calculated as 29.25%, and 23.59%, respectively. The total optimal production of electricity, methanol, and freshwater in the whole system is calculated at 62.86 MW, 1820.78 kg/h, and 63.88 kg/s, respectively. The dynamic analysis of the proposed system also showed that the production of methanol throughout the year will be higher using Municipal solid waste fuel than other fuels.