The following construction may be useful. It is not guaranteed to be optimal, because there are border effects, shaping effects and such. IIRC the densest lattice packing is the $D_4$-lattice (our library wanted their copy of Conway & Sloane back, so I cannot check). Here's the description. Specify a scale parameter $d$. Select points with coordinates $d(n_1,n_2,n_3,n_4),$ where $n_1,n_2,n_3,n_4$ are integers subject to the constraint that their sum must be even. Then the closest distance between two such points is $X=\sqrt{2}d$. The number of points $N$ in your hypercube would then be $N\approx \frac12 \left(\frac Wd\right)^4$.
Caveats: I may remember some things wrong, and the $D_4$ lattice is optimal with respect to some other figure of merit. Also, for some choices of $X$ (particularly when $d$ is relatively large with respect to $W$) you may benefit from jiggling the points around a bit and/or rotating the lattice. If my basic recollection is correct, then I doubt you can win much by such tricks, so if this simple, relatively easy to implement construction is good enough for your purposes, you may consider using it.
In full generality your problem probably cannot be answered. I mean, if you specify $W$ and $X$ (resp. $N$), the answer to the question of best $N$ (resp. $X$) may be unknown (read: very difficult).