The living environment is of vital importance to human beings and is also the basis for their survival and development. Along with the accumulation of people’s production and living experience, people are seeking their own development while studying the living environment more deeply. In recent years, various regions and departments have conscientiously implemented the relevant decisions and deployments. They have promoted the construction of rural infrastructure and the equalisation of basic public services between urban and rural areas, so that the rural living environment can be gradually improved. The rapid development of urban-rural integration has brought great opportunities and challenges for rural development, making rural development issues increasingly complex and affecting the effectiveness of the construction of a new rural habitat. At the same time, the agricultural economy is the basis of national economic development, and the ecological environment provides a certain amount of material environment for the development of the agricultural economy. Therefore, research on the harmonious development of the agricultural economy and the ecological environment has always been a hot issue for the authorities concerned. After all, China’s agricultural economic development mode is characterized by a rough-and-ready approach, and the agroecological environment continues to deteriorate, leaving the issue of sustainable agricultural development to be resolved. What is worse, in the practice of agricultural production, the related agricultural activities have brought serious pollution to the environment. Specifically, the carrying capacity of the agricultural ecological environment is declining, leading to an increasingly serious conflict between sustainable agricultural economic development and the construction of an environmentally friendly and resource-saving society. In China, although the industrialization process is accelerating, the agricultural population still accounts for a large proportion of the population. As people’s living standards continue to improve, a favorable living environment has become an urgent need for farmers. As a result, strengthening the construction of rural infrastructure, improving rural living conditions, and improving rural environmental sanitation are important issues that need to be addressed urgently. Therefore, to further investigate the impact of environmental regulation and agricultural economic efficiency on the habitat, this study constructs a systematic GMM model using panel data for 30 provinces and regions in China from 2011 to 2021.