Your landlord can still evict you for non-payment of rent, but he might not be able to get a money judgment for the unpaid rent (depending upon the extent of the building code violation). If you are renting the garage as living space, then your attorney might be able to defend on the grounds that the court should not enforce an illegal contract. However, you would still get evicted.
The answer depends on whether the outstanding violations are a substantial breach of the warranty of habitability under civil code 1941. In other words, do the violations amount to a significant health, safety, or sanitary violation? If they do, then breach of the warranty is a defense to an eviction. However, a judge or jury may find that the violation only amounts to a $300 rent credit per month, at which time you will have to pay all the back rent or get evicted. If you are able to pay at that time, then you would be allowed to stay.
Disclaimer: You should discuss your situation with a local attorney, as the above statement is a general overview and does not take into account all of the factual considerations in your case. Nothing in this statement creates an attorney-client relationship.