Mark values outside specific range as NaN

I’m calculating myBand using Raster —> BandMaths.

myBand values must be between minValue and maxValue.
So after calculating myBand, I’m calculating next, final band, using following expression:

if (myBand > maxValue || myBand < minValue) then NaN else myBand

I wonder if there’s any dedicated tool to filter values of one band instead or if I’m able to type both statements (one to calculate myBand and second to filter values) as one Band Maths expression.

You can set the valid pixel expression on the band

myBand.setValidPixelExpression(myBand < maxValue && myBand > minValue)

If you want to filter just a single value you can set the no-data value

myBand.setNoDataValue(42.24)
myBand.setNoDataValueUsed(true)

Note that you have to enable the usage of the no-data value.

Thank you for answer.
How this will behave when I save myBand as GeoTIFF?

This will not be applied. Only if you further work with SNAP. In other applications it will not be considered.
In this case you need to stick to your first approach.