To ensure food safety in the Beijing-Tianjin-Hebei region, the Yongqing County (Langfang City, Hebei Province) was selected as the research area. A total of 412 surface and 410 deep soil samples were collected to determine the concentration of eight heavy metals, i.e., As, Cd, Cr, Cu, Hg, Ni, Pb and Zn. Meanwhile, the enrichment factor and potential ecological risk were used to evaluate the degree of heavy metal pollution and ecological risk. The results showed that the average concentrations of eight heavy metals in surface (deep) soil in Yongqing region are As 9.44 mg/kg (8.93 mg/kg), Cd 0.16 mg/kg (0.10 mg/kg), Cr 64.4 mg/kg (62.3 mg/kg), Cu 24.6 mg/kg (20.7 mg/kg), Hg 0.41 mg/kg (0.20 mg/kg), Ni 27.7 mg/kg (27.7 mg/kg), Pb 20.7 mg/kg (18.2 mg/kg) and Zn 72.8 mg/kg (57.5 mg/kg), respectively. The spatial distribution of heavy metal concentration shows a pattern of high in the southwest and low in the northeast. Based on the enrichment factor (EF), the eight heavy metals could be divided into three categories: (1) Hg (2.18) is strongly influenced by human activities; (2) Pb (1.14), Cu (1.22), Zn (1.29) and Cd (1.63) are controlled by natural geological background and human activities; (3) Ni (1.01), Cr (1.05) and As (1.09) are mainly controlled by natural geological background. Results of the environmental quality assessment showed that the local soil is largely safe to use, and the risk area is only 1.1 km2, accounting for 0.14% of the total area. The area that meets the evaluation standards for green food production is about 756.62 km2, accounting for 99.43% of the total area. Among them, the area of irrigated land, dry land, orchards in accordance with the standard accounted for 98.94%, 99.29% and 99.59% of the total area of their respective land categories. In terms of ecological risk, the soil comprehensive ecological risk index of the local dryland, irrigated land and orchard agricultural land is largely low, accounting for 95.63%, 77.37% and 98.35%, respectively. Only dry land (0.13 km2) and irrigated land (0.03 km2) have a few higher ecological risk areas, which deserve further ecological evaluation. In conclusion, although heavy metal contents in some areas at Yongqing are affected by human activities, most areas have low ecological risk. In this study, the area that meets the evaluation standards for green food production and low comprehensive potential ecological risk is determined as the most suitable for large-scale green food production. This area is 669.12 km2, accounting for 87.93% of the total area. Our results provide a scientific basis for local production, planting and planning management of green agricultural products.