Targeted therapy and immunotherapy have emerged as treatment options for hepatocellular carcinoma (HCC) in recent years. The significance of serine and glycine metabolism in various cancers is widely acknowledged. This study aims to investigate their correlation with the prognosis and tumor immune microenvironment (TIME) of HCC. Based on the public database, different subtypes were identified by cluster analysis, and the prognostic model was constructed through regression analysis. The gene expression omnibus (GEO) data set was used as the validation set to verify the performance of the model. The survival curve evaluated prognostic ability. CIBERSORT was used to evaluate the level of immune cell infiltration, and maftools analyzed the mutations. DsigDB screened small molecule compounds related to prognostic genes. HCC was found to have two distinct subtypes. Subsequently, we constructed a risk score prognostic model through regression analysis based on serine and glycine metabolism-related genes (SGMGs). A nomogram was constructed based on risk scores and other clinical factors. HCC patients with a higher risk score showed a poor prognosis, and there were significant differences in immune cell infiltration between the high- and low-risk groups. In addition, three potential drugs associated with prognostic genes, streptozocin, norfloxacin, and hydrocotarnine, were identified. This study investigated the expression patterns of SGMGs and their relationship with tumor characteristics, resulting in the development of a novel model for predicting the prognosis of HCC patients. The study provides a reference for clinical prognosis prediction and treatment of HCC patients.