No, not 40 days.
An HBD season is around 175-176 days. A year of ML service time is 172 days. Any optional assignment to the minors that is less than 20 days counts as ML service time (which people tend not to fully understand, and where the "keep in minors for 20 days" rule of thumb comes from).
If your guy accrues 20 days of ML service time this season, you would need to leave him down for around 24-25 days next season to keep the extra arb year. That would be to cover the 20 days from this season, plus the "extra" 3-4 days between the difference of an ML service year and the length of the HBD season.
I'd go with (time accrued this season + 5 days) just to be safe.