You cannot have bond angles of 0 or 180 degrees in a Z-matrix. This is because the dihedral becomes degenerate. To solve this, you can add 'dummy atoms' which provide an auxiliary point of reference to remove the 180 degree angle. These atoms are usually denoted $\ce{X}$ or $\ce{Xx}$ in computational chemistry suites. Usually, dummy atoms are placed at 90 degrees to a pair of atoms and the third collinear atom is then defined with a bond angle of 90 degrees and a dihedral of 0 or 180 degrees with respect to the previous 3 atoms.
Example
To illustrate what I'm talking about, here's a schematic of your pair of molecules, with three dummy atoms:
This could have a Z-matrix like:
O 1
C 1 a
Xx 2 1.0 1 90
O 2 b 3 90 1 180
Xx 4 1.0 2 90 3 0
H 4 c 5 90 2 180
Xx 6 1.0 4 90 5 0
O 6 d 7 90 4 180
H 8 e 6 104.5 7 180
Notes
There are no hard and fast rules about how many you should use (obviously we could simply define subsequent dihedrals in terms of the leftmost dummy atom) however it's best to strive for locality so that small changes in some variable don't correspond to large displacements elsewhere, in which case rounding errors or large gradients can ruin your day. You could also have defined all of the dihedrals in your molecule with respect to that convenient non-collinear hydrogen, however this is the Z-matrix equivalent of spaghetti code.
You will note that I use different letters for each variable. This is because forcing the $\ce{H-O}$ and $\ce{C=O}$ bonds to be of equal length is probably an unrealistic constraint for a geometry optimisation of this system.
Finally, note that dummy atoms do not take part in the electronic structure of a molecule, so feel free to put them in anywhere and set the dummy atom 'bond' length to whatever you want. 1.0 Ångström is traditional as far as I know.
P.S.
Molden has a complete, if idiosyncratic graphical Z-matrix editor.