The gap is either provided intentionally, or is there by accident or by decision not to address it. If it is intentional, you would think it's providing ventilation for the attic (or cavity) space, as suggested already. But in that case, one has to put a barrier across that entire opening, to exclude pests (rodents, insects, birds, etc.). Which would call for either hardware cloth, or some other kind of screen which will not significantly impede the free movement of air through the opening.
In the other case, i.e. the gap is not supposed to be there, then it should be closed up with any material; hopefully a rigid one. Pest-blocking expanding foam could be effective but the foam would have to have enough of a nearby surface onto which it can adhere. If there is a gaping cavity behind the opening, then it's not clear that expanding foam will necessarily stick well. If that is a problem, then one would have to cut out the right shape and size of a closure strip ... rigid, weather-proof material, fasten it up there and then caulk the edges to seal things up properly. Larry