I have converted a shed into a home and have been living in it for the last 2 years. Recently, the county building officials said they are cutting power off to it because it is an illegal structure (which I did not realize when I moved in). If we live off grid, with our own power, septic and well, and we own the land, is there anything else the county or state can say or do about it? I have neighbors who live in similar or worse structures and nothing has been done to them. What are my rights in this situation? What am I allowed to do if I live off grid?
That will depend on state law, and possibly county or municipal law. Some states or localities can and do require a "certificate of occupancy" or some similar document certifying that a structure passes standards for human occupancy, and can and do prohibit living in a structure that does not pass. Others do not require a document but can condemn as unfit for human habitation a structure that does not meet minimum standards, and can order such a structure boarded upo or even demolished. What standards are applied, and what procedures must be followed, vary significantly depending on the state or locality.
Additional info specific to North Carolina:
A document from Charlotte NC gives its minimum housing code as:
The current Minimum Housing Code for the City of Charlotte specifies the following: (a) At least one room in the dwelling shall contain not less than 150 feet. (b) A kitchen-dining room combination, if any, shall be not less than 100 square feet. (c) A first bedroom, if any, shall be not less than 100 square feet. (d) A second bedroom, if any, shall be not less than 70 square feet. (e) There shall be at least 70 square feet in each habitable room. (f) There shall be at least 150 square feet of floor space in habitable rooms for the first occupant in each swelling unit; at least 100 square feet for each of the next three occupants; and at least 50 square feet for each additional occupant over the number of four. (Children one year of age and under shall not be counted). (g) There shall be at least 80 square feet of bedroom floor space for the first occupant; at least 20 square feet for the second occupant; and at least 30 square feet for each occupant over the number of two. (Children one year of age and under shall not be counted).
and goes on to say:
5.) What action can Code Enforcement take if occupancy standards are violated? There are two remedies to Minimum Housing Code violations as governed by the State Law. 1.) Repair, alter or improve the dwelling 2.) Vacate and close, and remove or demolish An order to repair for occupancy violations would suggest an expansion of the dwelling to support more occupants. An order to vacate, close and demolish must be approved by City Council as an ordinance before the city can implement that order.
This only applies to the city of Charlotte, but is an example of the sort of regulations that might apply.
The NC housing code says:
The State of North Carolina does not have a comprehensive property maintenance code. The state’s Landlord and Tenant law (Chapter 42), however, imposes minimum generic maintenance obligations for rental property. Also, state law (Chapter 160A) empowers localities to adopt and enforce ordinances for dwellings that are “unfit for human habitation” due to conditions that render dwellings “unsafe” to residents
Local Housing Ordinances North Carolina Chapter 160A empowers cities and counties to enact laws that provide for the repair, closing and demolition of dwellings found to be “unfit for human habitation” due to Housing Codes for North Carolina As of July 2008 See: www.healthyhomestraining.org Page 2 of 6 “dilapidation, defects increasing the hazards of fire, accidents or other calamities, lack of ventilation, light or sanitary facilities, or due to other conditions” that render the dwellings “unsafe or unsanitary, or dangerous or detrimental to the health, safety . . . [or] welfare of the residents.” § 160A-441. Localities also may enact ordinances for the “repair, closing or demolition of any abandoned structure” deemed to be “a health or safety hazard as a result of the attraction of insects or rodents, conditions creating a fire hazard, [or] dangerous conditions constituting a threat to children.” § 160A-441. Furthermore, this Chapter empowers localities to enact ordinances to require that every rental dwelling have a heating system so that at least one habitable room has a minimum temperature of 68 degrees Fahrenheit in winter. § 160A 443.1(a).
Thus the applicable laws and regulations, if any, will depend on local enactments, and how they are enforced will depend on local rules and custom. It may be a good idea to consult a lawyer who knows these local laws and procedures to determine exactly what an owner's rights are in such a case.
The answer by @DavidSiegel is a solid one and I won't repeat it. This answer addresses a side point in the original post:
I have neighbors who live in similar or worse structures and nothing has been done to them.
In general, selective enforcement of laws by governmental entities is allowed, so long as it is not made on the basis of an illegal consideration like race.
And, you can't prove illegal discrimination, even on the basis of an impermissible reason such as race, simply by statistical or anecdotal evidence, although that kind of evidence might be enough to make a "plausible" claim that would entitle you to more discovery regarding the reason for the enforcement against you and not others, in the course of a lawsuit.
There is a concept of an equal protection violation against a class of one which usually comes up in contexts like the one you describe, but it is very hard to establish and usually requires compelling evidence that someone has a grudge against you and is enforcing the laws in a way that they are not, as a matter of policy, enforcing against every one else, but are singling you out for reasons of personalized spite due to some unrelated dispute (e.g. you are the sheriff's husband's ex-girlfriend).