Power for either electrolysis or batteries comes from the electricity supply network. If this is fully decarbonized then, by definition, neither option produces any CO2 while in operation. However if the grid isn't decarbonized then the hydrogen option will produce more CO2, because more of the energy is wasted by converting to hydrogen and back than by charging and discharging a battery. If the availability of electricity is limited then batteries are better because by the same argument they use less of it.
This preference for battery in service needs to be balanced against the environmental downsides of the battery itself and of the fuel cell and hydrogen storage, any of which may include materials that have environmental downsides in their extraction, are scarce, or are difficult to re-use or recycle. From what I gather these are worse for the battery.
All the above excludes consideration of the "embodied carbon" in constructing the equipment, and any incidental CO2 production during a nominally carbon-neutral process. Vehicle emissions are also "amplified" if the technology used makes it larger or heavier, so requiring more energy to move it, possibly less passenger space, and more road maintenance.
By those measures something like Nottingham's CNG buses, using biogas from sewage treatment, may be just as green as either battery or hydrogen.