This can be a thorny subject. I think there is UCC, common law, Federal law, state law and most certainly case law. There are tons of cases helping determine what can and can not be setoff. You have to address bankruptcy, IRAs, pledges, etc.
We asked counsel for info on this and I have a 22 page document from 1990 addressing various issues with setoff. I am not able to share it, but want to emphasize how big this could be. You need to decide what part you want to understand. If it is critical, consult counsel. If it is general knowledge, do a Google search and focus on your state. Then look at your bank contracts and agreements for clauses.
My opinions are not necessarily my employers.
Rules and Regs minus Relationships equals Resentment and Rebellion. John Maxwell