Technically speaking, if you can play the PS3 version of the game, you'll be playing on the same servers as every other PS3 player in your region (or worldwide, depending on how the servers are configured). However, it is currently impossible to play the PS3 version of GTA 5 on PS4.
The PS4 is not backwards compatible to the PS3, and Sony has made no attempt to develop an emulator to make it possible. Instead, Sony has opted to provide backwards compatibility through PS Now (requires a monthly subscription fee separate from PS Plus), by letting people stream PS3 (and PS4) games on various devices, including PS4 and PC.
Unfortunately, even if you subscribe to PS Now (and pay for it), you still won't be able to play GTA 5, because the game is not yet available on PS Now. And while it's possible for GTA 5 to become available on PS Now in the future, there is no guarantee that it'll be the PS3 version.
If you can play the PS3 version of GTA 5, you can play with your friend online regardless of the platform you're on. However, as of now you can't, and there's no telling when you can (if you ever will).