Opioids are the primary regimens for perioperative analgesia with controversial effects on oncological survival. The underlying mechanism remains unexplored. This study developed survival-related gene co-expression networks based on RNA-seq and clinical characteristics from TCGA cohort. Two survival-related networks were identified, and drug-induced transcriptional profiles were predicted. Immune cell infiltration algorithm, least absolute shrinkage and selection operator (LASSO) regression, and cox proportional models were executed to explore the correlation between opioid-related drugs and prostate cancer patient prognosis. The opioid receptor agonists, represented by tramadol, were evidenced for anti-survival effects on prostate cancer by facilitating the DNA replication and cell cycle, and immune cell infiltration. Conversely, opioid receptor antagonists showed pro-survival effects. A novel prognostic model containing CNIH2, MCCC1, and Gleason scores was established and validated in two independent cohorts. This study revealed opioids' effect on prostate cancer progression, and provided a novel model to predict these regulations in clinical outcomes.