Use Euclidian divisions...
First, quick maths recall: All integers can be divided with the Euclidian division. An Euclidian division is quite simple, you divide a dividend D (your big number) by a divisor d (your small number you divide with) as much as you can, and when you cannot anymore you have both the quotient q (your result) and a remainder r (the rest). Mathematically, this is commonly shown like this:
D = d x q + r
In calendar terms, D is the total number of days every year, d is your number of months, q is your number of days per months and r is the annoying days you'll need to add back once in a while.
... Helped by your favorite spreadsheet software
All spreadsheet software (Excel, OpenOffice, Google Docs...) include functions to calculate the dividend, quotient and remainder. With this you can automate your calculations and test many values at once:
Above is an example using Excel, which took me about 10 minutes to set up. In Excel, the functions you'll use are QUOTIENT and MOD (modulo operation for the remainder). While there may be some differences between software, it should be quite similar across them.
Now to have the minimum remaining days every year, choose the lowest remainder all while keeping a meaningful quotient and divisor according to the size and the seasons-to-month relationship you wish. The remainder is what you'll need to add every once in a while. The simplest would be to add it every year on one or two months (like January having 31 days instead of 30), but you can also cumulate them every year and "spend" them later: If you want to add a 40 days month once in a while and your remainder is 2, then you'd wait 20 (40/2) years before adding a whole month back.
Remember however: the more you cumulate those days before paying the bills, the less the months will be bound together with the seasons. For instance, if you wait a full year before adding back a year, you'll drift off slowly over a 1018 year period having "January" be in winter at first, then being in summer then back to winter. It's perfectly doable but you need to take this into consideration.