A certificate of occupancy is typically a certification by the local inspectional services department that the property was inspected and conforms to the local requirements for occupancy at the time of inspection. In the case where a buyer is being required to obtain it, proceed very carefully. You should have a qualified licenced (if they are in your area) home inspector check out the property first to see what doesn't conform & what needs attention in addition to getting estimates from several licenced contractors to get an idea of the work that needs to be done, re-done, or removed PRIOR to accepting this type of contingency to any sale. You'll need to review what work has been done, what permits were applied for, what work doesn't have the needed permits & what will be needed to bring the property up to current requirements/standards.
The certificate of occupancy is usually not that expensive, the local inspectional services can tell you exactly what it will cost. What does get expensive is the labor & materials needed to get the property to conform if there is a problem with what's currently there.
Your mortgage lender will usually require a certificate of occupancy in order to lend on a property or you might have to get a construction loan.
Good luck, hope that helps