If you care about getting the really correct extension: Open the dat file in a hex editor (I use HxD on Windows). The very first byte of the file holds the Z-machine version, typically 3, 4 or 5.
What everybody above said + you don’t need to rename the file, you can open it as it is. Just change the filter in the bottom right corner. (Also, AMFV is z4, not z5).
In answer to the second part of your question, just redirect the output to a file. You can do this from the command line or a batch file (or equivalent if not using Windows). Something like this: