The answer depends on your definition of "neutralise".
For some people it is a matter of being dollar neutral. Then the answer is straightforward.
In your case it seems that you have also in mind a concept of zero expected returns. In this case the solution would be to invest 1 in $A$ and $-\mathbb{E}(r_B)/\mathbb{E}(r_A)$ in $B$. This is not a common choice.
For others, it means market neutral (or factor neutral with respect to a list of factors, that can be obtained via a PCA, or an expert-driven approach --like Axioma or BARRA factors--).
In this case, you want to orthogonalize the basket made of a fraction $p$ of the instrument $A$ and $(1-p)$ of the asset $B$ (in dollars) with respect to the space spanned by the returns of our list of factors $F_1,\ldots,F_K$.
You just have to project our basket on factors (say $\pi_A$, rest. $\pi_B$, is the projection of one dollar in risk of $A$, resp. $B$, projected on your set of factors), and to write that you search for $p$ such that
$$p \pi_A + (1-p) \pi_B=0.$$
But since the projections are vectors, it is not achievable in general, hence you should target
$$\min_p \|p \pi_A + (1-p) \pi_B\|^2.$$
The connect this with your question about the variance. Let say you want to minimise the variance, i.e.
$$\min_p (p r_A + (1-p) r_B)^\top \Omega\; (p r_A + (1-p) r_B),$$
where $\Omega$ is your covariance matrix for all the assets, and assume you can diagonalise our matrix $\Omega$ by block:
- one block is made of your factors $F_1,\ldots,F_K$
- and the rest is the standard PCA of the orthogonal of these factors.
If you work on the formulation, you will see that this expression can be split in two parts: one that corresponds to $F_1,\ldots,F_K$, with a variance coefficient $\lambda_F$, and another that corresponds to the orthogonal:
$$(p r_A + (1-p) r_B)^\top \Omega\; (p r_A + (1-p) r_B) = \lambda_F^2 \|p \pi_A + (1-p) \pi_B\|^2 + \lambda_0^2 \|p \pi'_A + (1-p) \pi'_B\|^2,$$
(where $\pi'$ is the projection in th orthogonal of $F_1,\ldots,F_K$) meaning that minimising the variance and being neutral to a set of factor is equivalent if your set of factors capture the essential of the variance of usual moves of returns.