Long term use of Prilosec has been linked to an increased risk of kidney disease and bone fractures. Taking it for two months under doctor's advice should be just fine. Sometimes, a doctor will prescribe it long term if the benefits outweigh the risks.
Prilosec isn't really for use for occasional heartburn because it can take up to four days to start relieving symptoms. Pepcid is very good for occasional heartburn; it can provide relief from reflux that starts within minutes.
I would recommend you take both the medications as prescribed, and I hope you will experience a full recovery.