With the implementation of 14th Five-Year Plan in China and the completion of the poverty alleviation task, the economy in China has made great progress. However, the carbon dioxide (CO2) emission has also increased, which will lead to the greenhouse effect for threatening economic development and affecting people's lives. Global warming has become the greatest challenge to contemporary economic and social development, and the transition to low-carbon economy has become a general trend of world economic development. Meanwhile, the traditional neural network method for predicting the economy and CO2 emissions is not accurate and objective because of the unbalanced labeling of training data and the inability to capture the relationship between time series data. Therefore, an economy and CO2 emission prediction model based on temporal attention Gate Recurrent Unit (GRU) (TA-GRU) with loss function Balanced Mean Square Error (BMSE) (BTA-GRU) mechanism is proposed to analyze and optimize the energy structure of 27 provincial-level administrative regions in China. Due to the unbalanced data labels in the different energy structure of different regions, the improved loss function BMSE is used to solve the problem of unbalanced labels from the perspective of statistics. Then, with coal, gasoline, petroleum, coke, fuel oil, diesel, natural gas and crude oil as inputs, the per capita Gross Domestic Product (GDP) as the desired output and the CO2 as the undesired output, the GRU can better capture time step dependencies in time series, and the attention mechanism can assign different weights to each time step, so that the proposed method can better learn data features and improve the accuracy of the an economic and CO2 emission prediction model. Finally, the CO2 emission and economic prediction model of different provincial-level administrative regions in China is established based on this proposed method. The experimental results show that compared with other mainstream time series data prediction models, this proposed model has better stability and practicability, and its mean absolute error (MAE), mean absolute percentage error (MAPE) and root mean square error (RMSE) reach 3.43, 3.28% and 2449.57, respectively. Furthermore, according to the actual situation of efficient provincial administrative regions, the energy structure of inefficient provincial administrative regions can be adjusted and optimized. Such as the energy structure of Hebei Province can be adjusted according to the energy structure of Beijing, it is estimated that the CO2 emissions of Hebei will be reduced by 82,972.43 ×10000 tons (WT) and its per capita GDP will be increased by 115,856 Yuan. Moreover, Chinese provincial governments should vigorously promote the use of clean energy, accelerate the establishment of a sound green low-carbon circular development economic system, and help achieve the goal of carbon neutrality.