Crits:
Let M = damage multiplier on crit. Let R = treat range. (i.e. for a 19-20/x2 weapon, M=2, R=2).
On the first attack roll, barring attacks against extremely high AC, the chance to hit is (A-T+21)/20. The chance to crit is R/20. A crit is worth (M-1) extra attacks, assuming the confirmation roll succeeds. Hence the expectation to-hit chance, when crits come into play, is:
(A-T+21)/20 +(A-T+21)*R*(M-1)/400
Factoring:
(A-T+21)(1 + R*(M-1)/20)/20
Note that the presence of crits affects this expression only through the appearance of the factor (1 + R*(M-1)/20). This is a constant multiplicative factor, and as such, has no effect on the location of the maximum (when the derivative of this thing is set equal to 0, all constants will vanish).
Now, there is a very slight error here. If you are in a situation where a 19, which normally threatens, misses, then the formula adds in some erroneous possible crit. damage on a 19. However, the error is very small, since the chance of a crit. is 1/400 in this case.