If you have the money to pay cash for the car. Then 0 months will save you the most money. There are of course several caveats. The money for the car has to be in a relatively liquid form. Selling stocks which would trigger taxes may make the pay cash option non-optimal. Paying cash for the car shouldn't leave you car rich but cash poor. Taking all your savings to pay cash would not be a good idea. Note: paying cash doesn't involve taking a wheelbarrow full of bills to the dealer; You can use a a check.
If cash is not an option then the longest time period balanced by the rates available is best. If the bank says x percent for 12-23 months, y percent for 24-47 months, Z percent for 48 to... It may be best to take the 47 month loan, because it keeps the middle rate for a long time. You want to lock in the lowest rate you can, for the longest period they allow. The longer period keeps the required minimum monthly payment as low as possible. The lower rate saves you on interest. Remember you generally can pay the loan off sooner by making extra or larger payments.
Leasing. Never lease unless you are writing off the monthly lease payment as a business expense. If the choice is monthly lease payments or depreciation for tax purposes the lease can make the most sense. If business taxes aren't involved then leasing only means that you have a complex deal where you finance the most expensive part of the ownership period, you have to watch the mileage for several years, and you may have to pay a large amount at the end of the period for damages and excess miles. Plus many times you don't end up with the car at the end of the lease.
In the United States one way to get a good deal if you have to get a loan: take the rebate from the dealer; and the loan from a bank/credit Union. The interest rate at banking institution is a better range of rates and length. Plus you get the dealer cash. Many times the dealer will only give you the 0% interest rate if you pay in 12 months and skip the rebate; where the interest paid to the bank will be less than the rebate.