Is there a way to detoxify from long term use of pain medication?

Yes, Multiple. It depends on your situation and which meds you have taken. Those containing Acetaminophen or nsaids like Ibuprofen can cause liver or kidney damage which needs to be addressed. Opiates can be reduced or tapered with or without medicine to reduce symptoms of withdrawal-meds such as Clonidine and/or suboxone (buprenorphine), it also depends on whether or not you have been abusing them. See a dr.