You have to get your H1B approved before OPT get expired.
If your OPT expired and your H1B is still pending. You are leagal to stay in US but can not work (can not get pay).
If your OPT expired and your H1B is still pending. You are leagal to stay in US but can not work (can not get pay).