Before a hard frost. The leaves can withstand a light frost, but you don't ever want the tubers to freeze. Once you have had the first light frosts and the plant is beginning to shrivel, dig it up. For me in zone 6, that would be already. I'm surprised if yours in zone 5 have still been blooming.
Cut the stems back to about 6", leave them hang somewhere indoors for a few days to dry, store in vermiculite or sand/sawdust etc in cool dark conditions (less than 50 degrees, but well above freezing).