From what I have gathered the answer to that question is largly dependant on your local and state ordinances. However the TTB (Feds) require that the brewery be in a standalone structure. so, as far as the feds are concerned you can sell your beer as long as your brewery is in a detached garage or shed or other out building or other standalone structure. You still have to fill out a brewers notice and provide a $1000.00 bond against the excise tax that you will have to pay.
Local regs, on the other hand, can be fairly restrictive. you have to deal with local zoning for what ever structure you intend to build or modify into your brewery, and town or county health codes relating to manufacture of foodstuffs, business licences, distribution/sales permits etcetera.
I was reading about a guy in Mariposa CA that managed all this for around 3k before learning that he needed a different location for a tasting room due to local health codes. However since that happened california has loosened restrictions on nano/micro breweries and tasting rooms to make the rules conform more or less with those for small wine producers who enjoy quite a few liberties here in cali.
so yeah, you can do it with a bit of leg work and some considerable hoop jumping. Seems like the real key is connecting with zoning and health inspectors who are willing to support you in your endevour.
can you tell what I have been thinking about doing?