Without knowing your exact setup, it is hard to say for sure. I can tell you that as a general rule, separate buildings will have separate electrical systems. They should only be supplying three wires to each building. Two hots and a neutral. At the entrance to each building you should have ground rods installed and tied into the panel at each building. That is where the ground neutral bond should be established.
This ground neutral connection is important because it provides two things. One is it helps prevent induced currents from nearby lighting strikes from damaging equipment in your house and possibly injuring people. It is also what clears a fault and prevents any metal objects in your house from becoming electrified. A grounding rod without a ground neutral connection, may have too high of an impedance to trip a breaker.
In general you do not want separate buildings sharing the same grounding system. When you have a main panel in one building, suppling a subpanel in another building the situation becomes more complicated, but I don't believe you have that.
As
@B-Mod mentioned, check your NEC code!
Code specifically calls for a N-G bond at the power source (I believe it says to do it at the "first means of disconnect".) and run 4 wires from there to any sub panel(s), where ground and neutral remain
SEPARATE on individual ground bar (connected to panel box) and neutral bar (isolated from panel box). The idea is that any ground fault will carry the whole way back to the bond at the source, and not carry on the neutral (grounded conductor). That connection to neutral (the N-G bond) will allow the ground fault to complete the circuit and trip the breaker.
Now where it gets interesting is when there are existing sub panel feeders in place with only 3 wires! In that case you
MUST bond again at the sub panel! The reason for this is that if you do not, and then have a ground fault,
IT WILL NOT TRIP THE BREAKER! That ground fault will carry back to the ground bar at that sub panel, and now the ground bar and the panel box are hot, and anyone touching them will get shocked! Not only that, but also
ALL ground wires going to outlets, switches, lights etc. are now hot and therefore anything with steel on it and a ground prong, will be hot.
To sum it up in short: ALWAYS make sure that the ground bar in each panel and sub panel is connected to the neutral EITHER in that panel
OR further upstream if there are 4 wires feeding it! Not both, or you have a parallel path from panel A to panel B on ground and neutral!
Also a note to the OP
@Anteclansing the N-G bond needs to be a permanent connection, not a plug type of device that creates a connection. If you use a plug device, you are dependent on that plug remaining plugged in, as well as the connection in the outlet that it is plugged into to be a good connection. If the contacts for some reason work loose, you will lose that connection! I do realize that when connecting to grid for backup things get interesting. But if this is a hardwired install, you have 1 electrical system (the inverter is just in the middle and managing the power flow to come from grid or from batteries/solar), therefore you need 1 bond! That bond will be the one at the service entrance, right where your power from the power company first lands at a breaker panel or service entrance disconnect. From there on, you should have a separate neutral and ground wire to all sub panels, as well as to your inverter, and on to your loads panel after the inverter! The "neutral in" vs the "neutral out" of the inverter should be common, but if they are not, then I would use a wire to physically connect neutral between the upstream and downstream sides of the inverter. If you set it up the way I just described, you will always have a neutral to ground bond from that first service entrance bond connection (regardless of the hot lines being connected from grid to inverter or not!), and this makes it way less confusing for anyone else who may work on the electrical system down the road!