Hello,
For out-of-stock scenario,
1. If the pharmacy you go to is a chain store, you can ask them to call around and see who has the medication you need. The store that has your medication can just pull your Rx through their system.
2. Even if it's not a chain store, you can also ask them to call other pharmacies (e.g. Walgreens, CVS, Walmart...etc). Once they find a store that has your medication, you can then request a "Rx transfer" from pharmacy A to pharmacy B. But this will usually take awhile to be done (a couple hours depending on how busy the pharmacies are).
For Expired Rx or no more refills on the Rx,
You can request a few pills as "emergency supply" through your pharmacy. It's usually given a 3 days supply until they get a hold with your doctor or obtained a new Rx. You can speed up the process by giving your doctor a call.