One should apply for Cap-Gap extension to extend the OPT period from it’s expiry date to H1B start date which is 1st October. Most people do this if they also applied for change of status from F1 to H1B so that they don’t have to leave the US however your COS from F1 to H1B has already been denied.
You must leave within 60 days of F1 or OPT expiry. F1 will only be valid till you are either enrolled in the college for a course of study or till your OPT expires.
You can keep working till your OPT expiry even if your COS from F1 to H1B is denied. However you can’t work beyond the expiry date on your OPT.