After the 3kg block is gently placed on the 1kg, then let, 1k +3kg = 4kg block and the spring be one system. For this mass spring system, there is so external force. (when oscillation takes place). The momentum should be conserved. Let, 4kg block has velocity v'.
When the blocks are going to the extreme position, there will be only potential energy.