Whether it is legal to sleep in office space is generally determined under local zoning ordinances and wouldn't be uniform across an entire state.
This said, the vast majority of localities would prohibit doing so under the relevant building and zoning ordinances of the municipality, or in unincorporated areas, the relevant building and zoning ordinances of the county. Typically, the penalty for doing so in violation of a local ordinance would be similar to the penalty for violating a minor to mid-grade misdemeanor, and each day you violate the ordinance would be a separate offense.
Typically, the question under a local ordinance would be how the office space is being used. If the office space is being used for residential purposes, the building owner and/or tenant under a lease would be violating the ordinance. But, an isolated instance of falling asleep at your desk during the work day would not normally be considered to be a residential use of the property.
If someone routinely spends the night at the office, not doing work, and has clothing and bedding and toiletries there, especially if the person doing so has no other residence, this would normally be treated as a residential use of the office building.
This said, local code enforcement officials have great discretion to enforce such ordinances strictly, or to ignore arguable violations of them. A private citizen (perhaps a neighbor, for example) has no authority to compel the local government in question to enforce its ordinances as strictly as the law would permit.