Recently, there have been many attempts to predict residential energy consumption using artificial neural networks. The optimization of these neural networks depends on the trial and error of the operator that lacks prior knowledge. They are also influenced by the initial values of the model based on the gradient algorithm and the size of the search space. In this paper, different kinds of hyperparameters are automatically determined by integrating particle swarm optimization (PSO) to CNN-LSTM network for forecasting energy consumption. Our findings reveal that the proposed optimization strategy can be used as a promising alternative prediction method for high prediction accuracy and better generalization capability. PSO achieves effective global exploration by eliminating crossover and mutation operations compared to genetic algorithms. To verify the usefulness of the proposed method, we use the household power consumption data in the UCI repository. The proposed PSO-based CNN-LSTM method explores the optimal prediction structure and achieves nearly perfect prediction performance for energy prediction. It also achieves the lowest mean square error (MSE) compared to conventional machine learning methods.