black and white grid

The asymmetric formulation somewhat conceals the symmetry of the problem. We're counting pairs of white and black squares that share at least one vertex.

Consider each internal vertex and the set of four squares adjacent to it. Two of them that share an edge are also together in the square set of another vertex, whereas those that are diagonally opposed are only together in the square set of this vertex. Thus, award half a point to the vertex for each pair of opposite-coloured squares that share an edge, and one point for each pair of opposite-coloured squares that are diagonally opposed. Then summing over all vertices will reproduce the desired score (if we treat the margins properly).

There are only four inequivalent configurations for the square set of a vertex:

  • All squares are the same colour: score $0$.
  • One square is a different colour than the other three: score $2$.
  • Two squares of each colour are diagonally opposed: score $2$.
  • Two squares of each colour share an edge: score $3$.

Thus, we should expect the optimal configuration to ideally have score $3$ at all internal vertices, with two squares of each colour sharing an edge. This is realized by alternating monochromatic rows or columns.

To turn this into a rigorous proof, you'll have to deal with the margins, but the fact that we can maximize the score in the bulk strongly suggests that the alternating row or column pattern should be optimal, at least for large $n$ where the bulk dominates the margins.

The total count from this solution is

$$ \frac{8+(3+3+4+4)(n-2)+6(n-2)^2}2=3n^2-5n+2\;. $$

This is OEIS sequence A049451 with an offset of $1$. The entry states that this is “With offset 1: the maximum possible sum of numbers in an $N\times N$ standard Minesweeper grid”, which is precisely your problem. Unfortunately, no reference to a proof is given.