You can file 6 months before H1 expires. You can also wait up to the 2nd last day and then file, but obviously that will be risky. So look at the current processing times of USCIS and file accordingly.
You do not need to get the stamping done right away. You can wait until you travel outside, but remember, you will need to get the visa stamped in order to reenter. You can also go to Canada or Mexico to get the stamping done, depends which one is closer.