I ran into this problem as well. If you think about this logically, just unpublishing the categories with no products could cause problems, especially if you have a tree like structure, where a category has sub categories. If those categories do not have products (which they may certainly not), those will be unpublished and your navigation structure may be crippled.
The way I'd do it is create a recursive script that traverses your nav structure, and eventually sets the published flag to 0, after you establish that it's ok to do so.
Mike Steyer
Information Systems Admin