Many cases for nonpayment of rent are ultimately settled. Generally, settlements cannot be appealed. So it's important to be careful what you agree to, because you'll be stuck with it unless you go back to Court again to revisit the dispute. Settlements are formalized in a legal document called a stipulation, which outlines the terms of what both sides agree to.
If you've withheld payment of rent due to bad conditions in your apartment or building, negotiate for a reduction in rent to compensate for the loss of services. This is called a "rent abatement." You should make sure repairs begin before you pay anything. Do not pay the full balance before repairs are done.
If you can't pay all the back rent due immediately, see if you can get the landlord to agree to a pay-out arrangement. The landlord's lawyer will usually say you can't have a rent abatement and an extension of time to pay, but there isn't any reason you can't have both if your negotiating hand is strong enough.
The reality is that most people aren't good negotiators, and even those who are skilled don't always do so well when they're negotiating for themselves. Tenant lawyers handle these negotiations all the time, and the concessions a legal professional gets are often far greater than what you are able to obtain by yourself. It's also a good idea to have your own attorney read the stipulation and explain it to you before you sign it.