Loss function for optimising precision & recall / sensitivity & specificity?
The comments raise two important points:

you can't directly optimize for sensitivity or specificity
you should save the model at the best epoch and use that one

Below I explain something that is not directly related, but might be interesting for you:
You can add the weights to the loss of some examples. For example, you can increase the weight of positive examples which means that the model will focus more on correctly classifying positive examples at the potential expense of negative examples. This is especially useful if your data is suffering from class imbalance.