Anaerobic digestion is a promising technology for treating bio wastes from energetic and environmental point of views. Co-digestion of wastes and process temperature are essential parameters that affect biogas production. In this study, comparing the effect of mesophilic and thermophilic anaerobic co-digestion of waste activated sludge and wheat straw at different mixing ratios is applied for sustainable biogas production based on energetic, environmental, and economic perspectives. Moreover, modeling and optimizing the process by using a time-series model and a partially connected recurrent neural network (RNN) based a slime mold algorithm (SMA) is established to calculate the optimal structure of the RNN model and the optimal values of its parameters such as the optimal number of neurons in the hidden layers, number of feedback connections, activation functions, and connection weights. The results show that the co-digestion of sludge and straw improves the carbon to nitrogen (C/N) ratio and enhances biogas production. The highest biogas production is recorded at C/N ratio of 33.15 and is approximately 30% higher in thermophilic digesters compared to mesophilic ones. Moreover, thermophilic digesters show higher chemical oxygen demand (COD) (75.38%) and total volatile solids (TVS) (72.37%) elimination than mesophilic digesters. The thermophilic digester increases the produced energy by 25.67% and decreases the production cost by 20.43% compared to the mesophilic digester in case using evacuated tube solar collectors. Furthermore, the RNN model could effectively predict biogas production, and the SMA could determine the optimal structure of the RNN model.