I'll prove that the maximum $M \leq 3nm - 2n - 2m + 2$.
First, note that if we assign to a bomb the number of non-bomb neighbors, the total sum doubles. Thus, we can obtain a more symmetric problem, which will be useful in what follows. (We could also just show that swapping all blank tiles with bombs and vice versa does not change the sum.)
For what follows, values will refer to the value in this alternate formulation.
Let there be a bomb in the interior of the board with seven clear neighbors (and thus, zero or one bomb neighbors). Then one of the orthogonally-adjacent cells has four known clear neighbors and one known bomb neighbor. (If there is no neighboring bomb, then choose any orthogonally-adjacent tile; if the neighboring bomb is orthogonally adjacent, choose the clear cell directly opposite the bomb; if the neighboring bomb is diagonal, then choose either of the cells on the two opposite edges.)
Since that cell has 4 clear neighbors and 1 bomb neighbor, it has a maximum value of 4 (if on the interior), and 1 (if on the border). Adding a bomb to that cell will add one to the values of its clear neighbors and not decrease its own value.
The same argument applies to clear cells with seven neighboring bombs.
So we see that we may assume that interior cells have a maximum value of 6.
Similarly, we will show that, optimally, border cells do not attain a value of 5.
For if a bomb on the border has five clear neighbors, the neighbor opposite the border has four clear neighbors and one bomb neighbor; the same argument as above applies.
So we may assume that border cells have a maximum value of 4.
So an upper bound for the maximum sum (in the original problem) is
\begin{align}
M & \leq \frac{1}{2}\left(6(m-2)(n-2) + 4(2(m-2) + 2(n-2)) + 3\cdot 4 \right) \\
& = 3(m-2)(n-2) + 5(m-2) + 5(n-2) + 6 \\
& = 3mn - 2m - 2n + 2.
\end{align}
We've only shown this upper bound for when $m,n \geq 2$, but this bound happens to work for the $1\times n$ case, where it reduces to $n$, which is greater that the actual maximum of $n-1$.
Note that a pattern of stripes, as shown by user ajotaxte, produces a lower bound of
$$M \geq 3mn - 3m - 2n + 2.$$
In conclusion, we see that the maximum for $m\times n$ grids, with $m \leq n$, is
$$ 3mn - 3m - 2n + 2 \leq M \leq 3mn - 2m - 2n + 2.$$