You can do this using a Before Commit event and an autonumber attribute.
if you start with a domain model along the lines of this. Where the number attribute will hold the invoice number and an attribute of type autonumber (will be the second number in the invoice number).
For the autonumber attribute you can define which number you want to start from.
Then you can add a Before Commit event handler and build a microflow similar to this.
The exclusive split uses the "isNew" function but you can also just check for empty on the invoice number attribute. The change object would build the string for your invoice number. You could use something along the lines of this.
formatDateTime([%CurrentDateTime%],'yyyy') + '-' + $Invoice/AutoNumber
Here is some documentation on event handlers and autonumbers
for the exclusive split, just add the code that i put in the annotation. isNew will return a boolean and you can set the true/false paths.
For your second question, since the number has to restart each year, then you wouldnt be able to use an autonumber to generate the number. You would have to build a table that would hold some kind of configuration for this.
If its just incremental and the number starts over from 1 (or some othere number) after the new year, then you can handle that logic in the before commit (or use an after commit event). If you change the autonumber attribute to an integer, you can retrieve the highest number from the database.
You would have to retrieve from database the first object where
year = the invoice year
use a sort on the integer attribute descending.
This will retrieve the last invoice number that was created, and then you can just add 1 to increment it.
If its more complicated then that, then you would have to create a configuration table, retrieve the configuration, and then do whatever logic necessary to set the invoice number.