Is it possible to know at what distance of the camera from the cube the height of the perspective projection of the cube will be equal to the height of the screen?

To conclude, in the case of distance, you either use a suited form of the angular diameter formula (the atan() or tan() one, depending on context) mentioned by everybody here from the beginning, or, if you already know the current apparent size at a given camera distance, just multiply the distance with the ratio between the current and the desired size, like I did in the above fiddle. To center things, simply look at the center of the projection.

The centering part will however alter the projection bounds (except for spheres, which look the same from every angle), so the only simple choice is to repeat the center + fit process until you get the desired outcome.