You can actually do both. You can concurrently file a cross-complaint for breach of the same lease agreement and/or you can raise this as an affirmative defense. For example, your answer can raise affirmative defenses such as:
"Defendant's obligations, if any, are extinguished by Plaintiff's breach of contract."
"Defendant is entitled to a setoff from any recovery Plaintiff obtains for all sums heretofore owed by Defendant with respect to the allegations in the Complaint."
Frank W. Chen has been licensed to practice law in California since 1988. The information presented here is general in nature and is not intended, nor should be construed, as legal advice. This posting does not create any attorney-client relationship with the author. For specific advice about your particular situation, consult your own attorney.
You would be better off doing both. You may have other defenses to the unpaid rent claims (such as failure to timely comply with return of security deposit funds or provide a timely written accounting as to how those funds were applied to any damages/unpaid rent claimed), which would defeat the landlord's recovery, and then you'd be able to get a judgment in your favor on your claims. Discuss this matter with a local California attorney who handles residential landlord tenant matters.
I agree with previous responses. I recommend you do both. However, if you are reluctant to file a separate cross-complaint, at least raise it as an affirmitive defense in your Answer.
This response is for information purpose only and does not constitute a legal advice. This response does not create an attorney-client relationship.