This study introduces a multi-energy complementary system that utilizes geothermal energy from oil wells for building heating and incorporates a thermal storage component to provide a flexible energy supply through efficient charging and discharging. The research centers on the design and optimization of a horizontal latent heat thermal energy storage (LHTES) unit, which is enhanced with a graded-porosity metal foam composite to accelerate the phase change process. A high-fidelity numerical model is employed to examine melting behavior and energy storage rates. The Taguchi method is applied to determine the optimal porosity distribution across six distinct zones within the composite. Analysis of variance demonstrates that porosity in the bottom two regions exerts the greatest influence on thermal performance. In comparison to the baseline case, which features uniform porosity of 0.99 in each sub-region, the optimized configuration reduces total melting time by 52.94% and increases the mean power rating (energy storage rate) by 105.67%. The structurally optimized LHTES-geothermal system also achieves superior economic performance, with the investment payback period reduced to 7 years, representing a 22% decrease relative to the 9-year baseline. Quantitative analysis over a 15-year lifespan shows that the optimized design yields 1.42 times the total profit of the reference scheme (Case 1 structure), thereby confirming its enhanced cost-effectiveness and economic viability. The core objective of this study is to reveal the universal laws and optimization design methods for the synergistic enhancement between gradient porosity foam metals and a standard, regular heat-conducting framework.