Hamiltonian BRST and Batalin-Vilkovisky Formalisms for Second Quantization of Gauge Theories