The pure technical view is that unlike batteries should never be mixed, nor should batteries of different ages. In practice, the battery case size (i.e. Group 27 or Group 31) is pretty much irrelevent but adding new batteries to old ones may not be. However, there is no significant danger of explosion or electrical problems - the worst that happens is that the old batteries drag down some of the power you might have gotten from the newer ones.
The bottom line is that you would be better off replacing the older 27's with new ones, either more 27's or 31's like you want to add. With 4 new batteries you would have a really strong battery bank that should age at the same rate. But if somebody gave you a couple new 31's and your 27's are not too old or in too poor a condition, you might go ahead and wire them up, since there is little financial risk to you if the life of the new 31's is shortened somewhat. The other choice is to simply replace the 27's with the new 31's, which will still give you a substantial boost in amp-hours.
If the 31's you obtained are used rather than new, all bets are off. They might be worse than the 27's you now have.