I would like to suggest two possible answers to your question.
The first would be, would it be possible for you take take the boolean raster (i.e. with 1 = cells above 40 and 0 cells bellow) and multiply that by the original dem. Doing this would "add back" the DEM elevation values (i.e. the hills). You would the have the hills extracted with their original elevation values.
The next possible solution would be to use a measure of Local Topographic Position (LTP) or some sort of Landform Classification tool. I don't know if QGIS has measures of LTP but I do know WhiteboxTools does. There is a plugin that you could download in QGIS (https://www.whiteboxgeo.com/manual/wbt_book/qgis_plugin.html) or you can download WhiteboxTools from their website (https://www.whiteboxgeo.com/).
For example, DifferenceFromMean tool in WhitheboxTools will take difference between the elevation of each grid cell and the mean elevation of the centering local neighbourhood. This could be helpful to identify upland areas (i.e. positive elevation). You could also try DeviationFromMean... this just just the deviation (i.e. normalized by Standard deviation) instead of the difference. There are also multi-scale equivalents for each of these tools, which take the max values over a range of spatial scales.
DiffFromMean (https://www.whiteboxgeo.com/manual/wbt_book/available_tools/geomorphometric_analysis.html#DiffFromMeanElev)
DevFromMean (https://www.whiteboxgeo.com/manual/wbt_book/available_tools/geomorphometric_analysis.html#devfrommeanelev)
MaxDiffFromMean (https://www.whiteboxgeo.com/manual/wbt_book/available_tools/geomorphometric_analysis.html#maxdifferencefrommean)
You could also try a Landform Classification tool as well. Something like Geomorphons or Pennock Landform Classification. These tools wont necessarily compute elevation values but instead will provide numeric/class values to represent the underlying feature. For Geomorphons, it will classify values by the following: Flat, Peak, Shoulder, Ridge, Convex, Slope, Concave, Footslope, Valley and Pit. It may be possible for you to use some combination of Peak, Shoulder and Ridge to potential extract "hills".
Geomorphons (https://www.whiteboxgeo.com/manual/wbt_book/available_tools/geomorphometric_analysis.html#geomorphons)
Pennock Landform Classification (https://www.whiteboxgeo.com/manual/wbt_book/available_tools/geomorphometric_analysis.html#pennocklandformclass)