They can talk to each other over that Thunderbolt connection.
I believe that you could set them up in Thunderbolt Bridge mode – so that the Thunderbolt connection acts in a similar way to an Ethernet network link. Once that network connection was configured, you could configure File Sharing or Screen Sharing. Note that Screen Sharing is NOT a way of allowing you use that iMac as a substitute for a real monitor.
You could also boot up one of the machines in Target Disk Mode or the equivalent. Then that machine would act as an external disk for the other. I don't see this as something one would want to do long-term – but there might be occasions where it would be handy.
Finally, if you were setting up the newer Mac from scratch, I believe that Migration Assistant could pull stuff from the old Mac over a Thunderbolt link.
But as for the iMac acting as a Target Display – nope. That ship sailed in Late 2014.