There's an addon
ZAutoStrip which automatically, well, strips you (places all equipment with durability into your bags) as soon as you drop combat. It doesn't always work (especially since the infamous combat pulses in raid dungeons), but it saved quite a lot of my repair bills.
I guess one could alter this or use some code to do what you desire.
IIRC it didn't work in WoW2, but with the "standard" changes (ipairs etc) it does now for me.