How can I prevent pain from an impacted tooth?

Prevention. If you have regular dental checkups with the appropriate x-rays that suggest an impacted tooth will eventually require removal, in most cases it is better to remove the tooth before you become symptomatic and before the roots are fully developed.
Pain. At 41 you should not be having pain from an impacted tooth. That may, or may not, be the source of your pain. Please see your Dentist for differential diagnosis and treatment or referral.
Dentist treatment. Ibuprofen is the best short-term treatment for tooth pain. Also Ibuprofen alternated with tylenol (acetaminophen) every 3 hours can help short term. You must see the dentist for a diagnosis and definitive treatment of your tooth pain.